diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedRequest.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedRequest.java index 5c76b6109..403d37a4f 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedRequest.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedRequest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.servlet; import java.util.Map; @@ -6,8 +21,19 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; +import org.ocpsoft.rewrite.event.Rewrite; +import org.ocpsoft.rewrite.servlet.spi.RequestParameterProvider; + +/** + * An {@link HttpServletRequestWrapper} for the {@link Rewrite} framework + * + * @author Lincoln Baxter, III + */ public abstract class RewriteWrappedRequest extends HttpServletRequestWrapper { + /** + * Get the current {@link RewriteWrappedRequest} + */ public static RewriteWrappedRequest getCurrentInstance(ServletRequest request) { RewriteWrappedRequest wrapper = (RewriteWrappedRequest) request.getAttribute(RewriteWrappedRequest.class @@ -15,15 +41,26 @@ public static RewriteWrappedRequest getCurrentInstance(ServletRequest request) return wrapper; } + /** + * Set the current {@link RewriteWrappedRequest} + */ protected static void setCurrentInstance(final RewriteWrappedRequest instance) { instance.setAttribute(RewriteWrappedRequest.class.getName(), instance); } + /** + * Create a new {@link RewriteWrappedRequest} + */ public RewriteWrappedRequest(HttpServletRequest request) { super(request); } + /** + * Get the current {@link Map} of modifiable {@link HttpServletRequest} parameters. + * + * @see {@link RequestParameterProvider} + */ abstract public Map getModifiableParameters(); } diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedResponse.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedResponse.java index 80a7b94c3..2c29b4dd5 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedResponse.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/RewriteWrappedResponse.java @@ -16,14 +16,19 @@ package org.ocpsoft.rewrite.servlet; import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponseWrapper; +import org.ocpsoft.rewrite.event.Rewrite; import org.ocpsoft.rewrite.servlet.config.response.ResponseContentInterceptor; import org.ocpsoft.rewrite.servlet.config.response.ResponseStreamWrapper; +/** + * A {@link HttpServletResponseWrapper} for the {@link Rewrite} framework. + * + * @author Lincoln Baxter, III + */ public abstract class RewriteWrappedResponse extends HttpServletResponseWrapper { protected final static String INSTANCE_KEY = RewriteWrappedResponse.class.getName() + "_instance"; @@ -38,41 +43,58 @@ public static RewriteWrappedResponse getCurrentInstance(ServletRequest request) private HttpServletRequest request; + /** + * Set the current {@link RewriteWrappedResponse} instance. + */ protected void setCurrentInstance(RewriteWrappedResponse instance) { request.setAttribute(RewriteWrappedResponse.INSTANCE_KEY, instance); } + /** + * Create a new {@link RewriteWrappedResponse} instance. + */ public RewriteWrappedResponse(HttpServletRequest request, HttpServletResponse response) { super(response); this.request = request; } + /** + * Get the {@link HttpServletRequest} to which this {@link RewriteWrappedResponse} is associated. + */ public HttpServletRequest getRequest() { return request; } - @Override - public ServletResponse getResponse() - { - return super.getResponse(); - } - - @Override - public void setResponse(ServletResponse response) - { - super.setResponse(response); - } - + /** + * Return true if any {@link ResponseContentInterceptor} instances have been registered on the current + * {@link HttpServletResponse}. + */ abstract public boolean isResponseContentIntercepted(); + /** + * Return true if any {@link ResponseStreamWrapper} instances have been registered on the current + * {@link HttpServletResponse}. + */ abstract public boolean isResponseStreamWrapped(); + /** + * Register a new {@link ResponseContentInterceptor} for the current {@link HttpServletResponse}. This method must be + * called before the {@link HttpServletRequest} has been passed to the underlying application.. + */ abstract public void addContentInterceptor(ResponseContentInterceptor stage); + /** + * Register a new {@link ResponseStreamWrapper} for the current {@link HttpServletResponse}. This method must be + * called before the {@link HttpServletRequest} has been passed to the underlying application.. + */ abstract public void addStreamWrapper(ResponseStreamWrapper wrapper); + /** + * Flush any content that may be buffered in registered {@link ResponseContentInterceptor} instances. This operation + * has no effect if no {@link ResponseContentInterceptor} instances are registered. + */ abstract public void flushBufferedContent(); } diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/ServletRegistration.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/ServletRegistration.java index d4450be17..17adc1954 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/ServletRegistration.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/ServletRegistration.java @@ -32,26 +32,41 @@ public class ServletRegistration private final List mappings = new ArrayList(); + /** + * Get the {@link Class} name of this {@link ServletRegistration}. + */ public String getClassName() { return className; } + /** + * Set the {@link Class} name of this {@link ServletRegistration}. + */ public void setClassName(String className) { this.className = className; } + /** + * Get the mappings for this {@link ServletRegistration}. + */ public List getMappings() { return mappings; } + /** + * Add a mapping to this {@link ServletRegistration}. + */ public void addMapping(String mapping) { this.mappings.add(mapping); } + /** + * Add all given mappings to this {@link ServletRegistration}. + */ public void addMappings(Collection mappings) { this.mappings.addAll(mappings); diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpCondition.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpCondition.java index f659b606b..0680be07e 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpCondition.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpCondition.java @@ -15,6 +15,7 @@ */ package org.ocpsoft.rewrite.servlet.config; +import org.ocpsoft.rewrite.config.Condition; import org.ocpsoft.rewrite.config.DefaultConditionBuilder; import org.ocpsoft.rewrite.context.EvaluationContext; import org.ocpsoft.rewrite.event.Rewrite; @@ -28,8 +29,10 @@ public abstract class HttpCondition extends DefaultConditionBuilder { /** - * Evaluate this condition against the given {@link org.ocpsoft.rewrite.servlet.http.event.HttpServletRewrite} event. If this condition does not apply to - * the given event, it must return false. If the condition applies and is satisfied, return true. + * Evaluate this {@link Condition} against the given + * {@link org.ocpsoft.rewrite.servlet.http.event.HttpServletRewrite} event. If this condition does not apply to the + * given event, it must return false. If the condition applies and is satisfied, return + * true. */ public abstract boolean evaluateHttp(final HttpServletRewrite event, EvaluationContext context); diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationCacheProvider.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationCacheProvider.java index e1a53a00b..59f3f19ef 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationCacheProvider.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationCacheProvider.java @@ -1,13 +1,29 @@ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.servlet.config; import javax.servlet.ServletContext; +import org.ocpsoft.rewrite.config.ConfigurationProvider; import org.ocpsoft.rewrite.spi.ConfigurationCacheProvider; /** - * Configuration cache provider for HTTP/Servlet environments. + * {@link ConfigurationCacheProvider} for HTTP/Servlet environments. * - * @see org.ocpsoft.rewrite.config.ConfigurationProvider + * @see ConfigurationProvider * @author Lincoln Baxter, III * */ diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationProvider.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationProvider.java index c4f0ff804..05e21dad7 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationProvider.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/HttpConfigurationProvider.java @@ -20,9 +20,8 @@ import org.ocpsoft.rewrite.config.ConfigurationProvider; /** - * Configuration provider for HTTP/Servlet environments. + * {@link ConfigurationProvider} for HTTP/Servlet environments. * - * @see org.ocpsoft.rewrite.config.ConfigurationProvider * @author Lincoln Baxter, III * */ diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/event/SubflowTask.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/event/SubflowTask.java index ae1f640f4..650e0868b 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/event/SubflowTask.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/event/SubflowTask.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.servlet.event; import org.ocpsoft.rewrite.context.EvaluationContext; diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteLifecycleContext.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteLifecycleContext.java index 0ed905099..18c3452fd 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteLifecycleContext.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteLifecycleContext.java @@ -1,3 +1,18 @@ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.servlet.http; import javax.servlet.Servlet; diff --git a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteProvider.java b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteProvider.java index 78cd1390f..f4790056e 100644 --- a/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteProvider.java +++ b/api-servlet/src/main/java/org/ocpsoft/rewrite/servlet/http/HttpRewriteProvider.java @@ -43,5 +43,8 @@ public final void rewrite(Rewrite event) rewriteHttp((HttpServletRewrite) event); } + /** + * Handle the current {@link HttpServletRewrite} event. + */ public abstract void rewriteHttp(HttpServletRewrite event); } diff --git a/api-tests/src/test/java/org/ocpsoft/rewrite/config/ConfigurationBuilderTest.java b/api-tests/src/test/java/org/ocpsoft/rewrite/config/ConfigurationBuilderTest.java index 59abd092d..aeeeed6a7 100644 --- a/api-tests/src/test/java/org/ocpsoft/rewrite/config/ConfigurationBuilderTest.java +++ b/api-tests/src/test/java/org/ocpsoft/rewrite/config/ConfigurationBuilderTest.java @@ -190,6 +190,7 @@ public void testWhereAPI() throws Exception .addRule() .when(new True()) .perform(operation) + .otherwise(operation) .where("p").bindsTo(El.property("whee.glee")).matches("blah") .constrainedBy(null).convertedBy(null).transformedBy(null).validatedBy(null) .where("s").matches("oh").bindsTo(El.property("ee.flee")) diff --git a/api-tests/src/test/java/org/ocpsoft/rewrite/param/ParameterizedPatternTest.java b/api-tests/src/test/java/org/ocpsoft/rewrite/param/ParameterizedPatternTest.java index 36a906551..d2ff9f31d 100644 --- a/api-tests/src/test/java/org/ocpsoft/rewrite/param/ParameterizedPatternTest.java +++ b/api-tests/src/test/java/org/ocpsoft/rewrite/param/ParameterizedPatternTest.java @@ -41,8 +41,7 @@ public static void initialize(ParameterStore store, Parameterized parameterized) { Set names = parameterized.getRequiredParameterNames(); for (String name : names) { - if (!store.contains(name)) - store.put(name, new DefaultParameter(name)); + store.get(name, new DefaultParameter(name)); } parameterized.setParameterStore(store); diff --git a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java index 168707718..c7e53949a 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java +++ b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java @@ -175,8 +175,8 @@ private Configuration build(Object context) List list = priorityMap.get(integer); for (final Rule rule : list) { result.addRule(rule); - - if(rule instanceof RuleBuilder) { + + if (rule instanceof RuleBuilder) { ParameterizedCallback callback = new ParameterizedCallback() { @Override public void call(Parameterized parameterized) @@ -185,9 +185,7 @@ public void call(Parameterized parameterized) ParameterStore store = ((RuleBuilder) rule).getParameterStore(); for (String name : names) { - if (!store.contains(name)) { - store.put(name, new DefaultParameter(name).bindsTo(Evaluation.property(name))); - } + store.get(name, new DefaultParameter(name)).bindsTo(Evaluation.property(name)); } parameterized.setParameterStore(store); diff --git a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleBuilderOtherwise.java b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleBuilderOtherwise.java index 4ee338953..9ae349ada 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleBuilderOtherwise.java +++ b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleBuilderOtherwise.java @@ -24,7 +24,6 @@ */ public interface ConfigurationRuleBuilderOtherwise extends ConfigurationBuilderRoot { - /** * Set the ID for the current {@link Rule}. This may be used in logging and for rule lookup purposes. */ diff --git a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java index fd52f8994..1a70022d9 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java +++ b/api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationRuleParameterBuilder.java @@ -36,7 +36,6 @@ public class ConfigurationRuleParameterBuilder extends ParameterBuilderLincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.config; + +/** + * A {@link ConfigurationRuleParameter} with a where clause. + * + * @author Lincoln Baxter, III + */ public interface ConfigurationRuleParameterWhere extends ConfigurationRuleParameter { diff --git a/api/src/main/java/org/ocpsoft/rewrite/config/Relocatable.java b/api/src/main/java/org/ocpsoft/rewrite/config/Relocatable.java index 85a048e21..c897adadd 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/config/Relocatable.java +++ b/api/src/main/java/org/ocpsoft/rewrite/config/Relocatable.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.config; /** diff --git a/api/src/main/java/org/ocpsoft/rewrite/config/RuleBuilder.java b/api/src/main/java/org/ocpsoft/rewrite/config/RuleBuilder.java index 6ad3de8be..480a3340f 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/config/RuleBuilder.java +++ b/api/src/main/java/org/ocpsoft/rewrite/config/RuleBuilder.java @@ -205,7 +205,7 @@ public ParameterBuilder where(String name) { ParameterBuilder parameter = new ParameterBuilder(name) {}; // FIXME: This cast isn't very nice. - return (ParameterBuilder) getParameterStore().where(name, parameter); + return (ParameterBuilder) getParameterStore().get(name, parameter); } } diff --git a/api/src/main/java/org/ocpsoft/rewrite/param/DefaultParameterStore.java b/api/src/main/java/org/ocpsoft/rewrite/param/DefaultParameterStore.java index 74c69763d..3768a085d 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/param/DefaultParameterStore.java +++ b/api/src/main/java/org/ocpsoft/rewrite/param/DefaultParameterStore.java @@ -20,6 +20,8 @@ import java.util.Map; import java.util.Map.Entry; +import org.ocpsoft.common.util.Assert; + /** * {@link Parameter} store which retains the order, bindings, and names of parameters contained within. */ @@ -27,26 +29,30 @@ public class DefaultParameterStore implements ParameterStore { private final Map> parameters = new LinkedHashMap>(); - public ConfigurableParameter where(final String param, ConfigurableParameter deflt) + public ConfigurableParameter get(final String name, ConfigurableParameter deflt) { ConfigurableParameter parameter = null; - if (parameters.get(param) != null) + if (parameters.get(name) != null) { - parameter = parameters.get(param); + parameter = parameters.get(name); } else { parameter = deflt; - parameters.put(param, parameter); + parameters.put(name, parameter); } + + if (parameter == null) + throw new IllegalArgumentException("No such parameter [" + name + "] exists."); + return parameter; } - public ConfigurableParameter get(String key) + public ConfigurableParameter get(String name) { - if (!parameters.containsKey(key)) - throw new IllegalArgumentException("No such parameter [" + key + "] exists."); - return parameters.get(key); + if (!parameters.containsKey(name)) + throw new IllegalArgumentException("No such parameter [" + name + "] exists."); + return parameters.get(name); } public boolean isEmpty() @@ -54,9 +60,10 @@ public boolean isEmpty() return parameters.isEmpty(); } - public ConfigurableParameter put(String key, ConfigurableParameter value) + public ConfigurableParameter store(ConfigurableParameter value) { - return parameters.put(key, value); + Assert.notNull(value, "Parameter to store must not be null."); + return parameters.put(value.getName(), value); } public int size() diff --git a/api/src/main/java/org/ocpsoft/rewrite/param/ParameterStore.java b/api/src/main/java/org/ocpsoft/rewrite/param/ParameterStore.java index bcff93262..209a584a3 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/param/ParameterStore.java +++ b/api/src/main/java/org/ocpsoft/rewrite/param/ParameterStore.java @@ -22,15 +22,34 @@ */ public interface ParameterStore extends Iterable>> { - public ConfigurableParameter where(final String param, ConfigurableParameter deflt); + /** + * Get the {@link Parameter} with the given name. + * + * @throws IllegalArgumentException if the {@link Parameter} with the given name does not exist. + */ + public ConfigurableParameter get(String name) throws IllegalArgumentException; - public ConfigurableParameter get(String key); + /** + * Retrieve the {@link Parameter} with the given name, otherwise use the default, if supplied. + * + * @throws IllegalArgumentException if the {@link Parameter} with the given name does not exist and no default was + * supplied. + */ + public ConfigurableParameter get(final String name, ConfigurableParameter deflt); + /** + * Return true if this {@link ParameterStore} is empty, otherwise return false. + */ public boolean isEmpty(); - public ConfigurableParameter put(String key, ConfigurableParameter value); - + /** + * Return the number of {@link Parameter} instances in this {@link ParameterStore}. + */ public int size(); + /** + * Return true if this {@link ParameterStore} contains a {@link Parameter} with the given name, + * otherwise return false. + */ public boolean contains(String name); } diff --git a/api/src/main/java/org/ocpsoft/rewrite/param/Transform.java b/api/src/main/java/org/ocpsoft/rewrite/param/Transform.java index a77561e11..511e763e3 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/param/Transform.java +++ b/api/src/main/java/org/ocpsoft/rewrite/param/Transform.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.param; import org.ocpsoft.rewrite.context.EvaluationContext; diff --git a/api/src/main/java/org/ocpsoft/rewrite/spi/RewriteResultHandler.java b/api/src/main/java/org/ocpsoft/rewrite/spi/RewriteResultHandler.java index 9177361b2..3b97e5867 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/spi/RewriteResultHandler.java +++ b/api/src/main/java/org/ocpsoft/rewrite/spi/RewriteResultHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.spi; import org.ocpsoft.common.pattern.Specialized; diff --git a/api/src/main/java/org/ocpsoft/rewrite/util/Instances.java b/api/src/main/java/org/ocpsoft/rewrite/util/Instances.java index 19dcfb2db..3e1c67aee 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/util/Instances.java +++ b/api/src/main/java/org/ocpsoft/rewrite/util/Instances.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.util; import java.util.Collections; diff --git a/api/src/main/java/org/ocpsoft/rewrite/util/ParameterUtils.java b/api/src/main/java/org/ocpsoft/rewrite/util/ParameterUtils.java index 33a2dfe9b..c00bde9ff 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/util/ParameterUtils.java +++ b/api/src/main/java/org/ocpsoft/rewrite/util/ParameterUtils.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.util; import java.util.ArrayList; @@ -31,8 +46,7 @@ public static void initialize(ParameterStore store, Parameterized parameterized) { Set names = parameterized.getRequiredParameterNames(); for (String name : names) { - if (!store.contains(name)) - store.put(name, new DefaultParameter(name)); + store.get(name, new DefaultParameter(name)); } parameterized.setParameterStore(store); diff --git a/api/src/main/java/org/ocpsoft/rewrite/util/ValueHolderUtil.java b/api/src/main/java/org/ocpsoft/rewrite/util/ValueHolderUtil.java index f260b5aca..4acf1c610 100644 --- a/api/src/main/java/org/ocpsoft/rewrite/util/ValueHolderUtil.java +++ b/api/src/main/java/org/ocpsoft/rewrite/util/ValueHolderUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.util; import java.lang.reflect.Array; @@ -7,6 +22,12 @@ import org.ocpsoft.rewrite.context.EvaluationContext; import org.ocpsoft.rewrite.event.Rewrite; +/** + * Utility for interacting with {@link Validator} and {@link Converter} instances. + * + * @author Lincoln Baxter, III + * + */ public final class ValueHolderUtil { @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/api/src/test/java/org/ocpsoft/rewrite/util/CompositeMapTest.java b/api/src/test/java/org/ocpsoft/rewrite/util/CompositeMapTest.java index 257281e9f..25b809543 100644 --- a/api/src/test/java/org/ocpsoft/rewrite/util/CompositeMapTest.java +++ b/api/src/test/java/org/ocpsoft/rewrite/util/CompositeMapTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.util; import java.util.HashMap; diff --git a/api/src/test/java/org/ocpsoft/rewrite/util/MapsTest.java b/api/src/test/java/org/ocpsoft/rewrite/util/MapsTest.java index 01253da86..aa697c8b8 100644 --- a/api/src/test/java/org/ocpsoft/rewrite/util/MapsTest.java +++ b/api/src/test/java/org/ocpsoft/rewrite/util/MapsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Lincoln Baxter, III + * + * Licensed 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.ocpsoft.rewrite.util; import java.util.List; diff --git a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Join.java b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Join.java index 6c16d0314..575f2c080 100644 --- a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Join.java +++ b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Join.java @@ -22,13 +22,25 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * {@link org.ocpsoft.rewrite.config.Rule} that creates a bi-directional rewrite rule between an externally facing path + * and an internal server resource path. + * + * @author Lincoln Baxter, III + */ @Inherited @Documented @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Join { + /** + * The external path to which the resource will be exposed. + */ String path(); + /** + * The internal resource to be exposed. + */ String to(); } diff --git a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Matches.java b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Matches.java index e1d028996..ccb9670ed 100644 --- a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Matches.java +++ b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Matches.java @@ -21,12 +21,20 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.regex.Pattern; +/** + * Configure the regular expression {@link Pattern} to which an {@link Parameter} must match. Used in conjunction with + * elements annotated with {@link Parameter}. + */ @Inherited @Documented @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Matches { + /** + * The regular expression to which the annotated element must match. + */ String value(); } diff --git a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/PathPattern.java b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/PathPattern.java index 8af0c1509..17556fc7a 100644 --- a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/PathPattern.java +++ b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/PathPattern.java @@ -22,11 +22,22 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.ocpsoft.rewrite.servlet.config.Path; + +/** + * Sets the {@link Path} to which the current {@link Rule} will match. Note, this annotation may be used without a + * corresponding {@link Rule} annotation. + * + * @author Lincoln Baxter, III + */ @Inherited @Documented @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface PathPattern { + /** + * The path to which the current {@link Rule} will match. + */ String value(); } diff --git a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Rule.java b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Rule.java index eafb553b5..4a3553681 100644 --- a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Rule.java +++ b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Rule.java @@ -25,8 +25,8 @@ import org.ocpsoft.rewrite.config.RuleBuilder; /** - * Sets the ID of the current rule. Same as calling {@link RuleBuilder#withId(String)}. This is an optional annotation, - * as rules do not require names. + * Sets the ID of the current {@link Rule}. Same as calling {@link RuleBuilder#withId(String)}. This is an optional + * annotation, as rules do not require names. * * @author Christian Kaltepoth */ diff --git a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Validate.java b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Validate.java index eaaf28257..08b51b5a9 100644 --- a/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Validate.java +++ b/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Validate.java @@ -22,13 +22,27 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.ocpsoft.rewrite.bind.Validator; + +/** + * Specifies a {@link Validator} with which to validate the corresponding {@link Parameter}. Used in conjunction with + * elements annotated with {@link Parameter}. + * + * @author Lincoln Baxter, III + */ @Inherited @Documented @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Validate { + /** + * The {@link Validator} type, to perform type-based lookups.. + */ Class with() default Object.class; + /** + * The {@link Validator} id, to perform name-based lookups. + */ String id() default ""; } diff --git a/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QueryEncodingTest.java b/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QueryEncodingTest.java index 2c61cf97e..4141d04c0 100644 --- a/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QueryEncodingTest.java +++ b/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QueryEncodingTest.java @@ -67,7 +67,7 @@ public void before() @Test public void testQueryStringMatchesWithParameters() { - store.where("my cat", new DefaultParameter("my cat")); + store.get("my cat", new DefaultParameter("my cat")); Assert.assertTrue(Query.parameterExists("my cat").evaluate(rewrite, context)); } @@ -88,7 +88,7 @@ public void testQueryStringMatchesLiteral() @Test public void testQueryStringMatchesPattern() { - store.where("x", new DefaultParameter("x")).constrainedBy(new RegexConstraint(".*&one=1.*")); + store.get("x", new DefaultParameter("x")).constrainedBy(new RegexConstraint(".*&one=1.*")); Query query = Query.matches("{x}"); query.setParameterStore(store); Assert.assertTrue(query.evaluate(rewrite, context)); @@ -97,7 +97,7 @@ public void testQueryStringMatchesPattern() @Test public void testQueryStringBindsToEntireValue() { - store.where("x", new DefaultParameter("x")).constrainedBy(new RegexConstraint(".*&one=1.*")); + store.get("x", new DefaultParameter("x")).constrainedBy(new RegexConstraint(".*&one=1.*")); Query query = Query.matches("{x}"); query.setParameterStore(store); Assert.assertTrue(query.evaluate(rewrite, context)); diff --git a/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QuerySimpleTest.java b/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QuerySimpleTest.java index d8dcfa501..b4b0a12fa 100644 --- a/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QuerySimpleTest.java +++ b/config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/QuerySimpleTest.java @@ -72,7 +72,7 @@ public void testQueryStringMatchesLiteral() @Test public void testQueryStringMatchesPattern() { - store.where("t", new DefaultParameter("t")); + store.get("t", new DefaultParameter("t")); Query query = Query.matches("foo=bar{t}"); query.setParameterStore(store); Assert.assertTrue(query.evaluate(rewrite, context)); @@ -83,7 +83,7 @@ public void testQueryStringParameterExists() { Query query = Query.parameterExists("foo"); query.setParameterStore(store); - store.where("foo", new DefaultParameter("foo")); + store.get("foo", new DefaultParameter("foo")); Assert.assertTrue(query.evaluate(rewrite, context)); } @@ -92,7 +92,7 @@ public void testQueryStringUnvaluedParameterExists() { Query query = Query.parameterExists("ee"); query.setParameterStore(store); - store.where("ee", new DefaultParameter("ee")); + store.get("ee", new DefaultParameter("ee")); Assert.assertTrue(query.evaluate(rewrite, context)); }