Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor 'org.codehaus' -> 'org.grails' for 'grails-core'

  • Loading branch information...
commit b672cb18969c73c4ac0cb0fc3f2f4597da77b7c1 1 parent 5840984
graemerocher authored
Showing with 986 additions and 1,372 deletions.
  1. +0 −8 grails-aether/src/main/groovy/org/codehaus/groovy/grails/resolve/maven/aether/AetherDependencyManager.groovy
  2. +25 −0 grails-compatibility/src/main/groovy/org/codehaus/groovy/grails/support/proxy/EntityProxyHandler.groovy
  3. +8 −7 ...va → grails-compatibility/src/main/groovy/org/codehaus/groovy/grails/support/proxy/ProxyHandler.groovy
  4. +4 −0 grails-core/src/main/groovy/grails/config/Settings.groovy
  5. +1 −1  ...core/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/AbstractGrailsApplication.java
  6. +2 −3 grails-core/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/AbstractGrailsClass.java
  7. +1 −3 .../src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/AbstractInjectableGrailsClass.java
  8. +119 −119 grails-core/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/DefaultArtefactInfo.java
  9. +16 −13 ...-core/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/DefaultGrailsApplication.java
  10. +1 −1  grails-core/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/DefaultGrailsClass.java
  11. +2 −1  ...re/src/main/groovy/{org/codehaus/groovy/grails/commons → grails/core}/StandaloneGrailsApplication.java
  12. +1 −1  ...core/src/main/groovy/{org/codehaus/groovy/grails → grails/core}/support/proxy/DefaultProxyHandler.java
  13. +1 −1  ...-core/src/main/groovy/{org/codehaus/groovy/grails → grails/core}/support/proxy/EntityProxyHandler.java
  14. +1 −1  grails-core/src/main/groovy/{org/codehaus/groovy/grails → grails/core}/support/proxy/ProxyHandler.java
  15. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/ControllerArtefactHandler.java
  16. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsControllerClass.java
  17. +2 −1  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClass.java
  18. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClassProperty.java
  19. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsServiceClass.java
  20. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsTagLibClass.java
  21. +1 −0  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsUrlMappingsClass.java
  22. +1 −1  grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/AbstractGrailsPlugin.java
  23. +4 −4 grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/CoreGrailsPlugin.groovy
  24. +1 −1  grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/MockGrailsPluginManager.java
  25. +1 −1  grails-core/src/main/groovy/org/{codehaus/groovy/grails → grails/beans}/support/PropertiesEditor.java
  26. +1 −1  grails-core/src/main/groovy/org/grails/core/support/GrailsApplicationFactoryBean.java
  27. +1 −1  .../{codehaus/groovy/grails/commons/cfg → grails/spring/context/support}/GrailsPlaceholderConfigurer.java
  28. +1 −1  ...ovy/grails/commons/cfg → grails/spring/context/support}/MapBasedSmartPropertyOverrideConfigurer.groovy
  29. +1 −1  .../test/groovy/org/codehaus/groovy/grails/commons/cfg/GrailsPlaceHolderConfigurerCorePluginRuntimeSpec.groovy
  30. +2 −1  grails-core/src/test/groovy/org/codehaus/groovy/grails/commons/cfg/GrailsPlaceholderConfigurerSpec.groovy
  31. +1 −1  ...c/test/groovy/org/codehaus/groovy/grails/context/support/PluginAwareResourceBundleMessageSourceTests.groovy
  32. +1 −1  grails-core/src/test/groovy/org/codehaus/groovy/grails/core/io/ResourceLocatorSpec.groovy
  33. +1 −1  grails-core/src/test/groovy/org/codehaus/groovy/grails/plugins/BinaryPluginSpec.groovy
  34. +1 −0  grails-plugin-codecs/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsCodecClass.java
  35. +2 −2 ...ls-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/ControllersGrailsPlugin.groovy
  36. +672 −36 grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java
  37. +0 −190 grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RedirectDynamicMethod.java
  38. +9 −617 grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RenderDynamicMethod.java
  39. +1 −1  ...-controllers/src/test/groovy/org/codehaus/groovy/grails/compiler/web/ControllerDomainTransformerSpec.groovy
  40. +2 −2 grails-plugin-converters/src/main/groovy/grails/converters/XML.java
  41. +2 −2 .../src/main/groovy/org/codehaus/groovy/grails/web/converters/configuration/ChainedConverterConfiguration.java
  42. +1 −1  ...verters/src/main/groovy/org/codehaus/groovy/grails/web/converters/configuration/ConverterConfiguration.java
  43. +2 −2 ...main/groovy/org/codehaus/groovy/grails/web/converters/configuration/ConvertersConfigurationInitializer.java
  44. +2 −2 .../src/main/groovy/org/codehaus/groovy/grails/web/converters/configuration/DefaultConverterConfiguration.java
  45. +2 −2 ...rc/main/groovy/org/codehaus/groovy/grails/web/converters/configuration/ImmutableConverterConfiguration.java
  46. +1 −1  ...rs/src/main/groovy/org/codehaus/groovy/grails/web/converters/marshaller/json/DeepDomainClassMarshaller.java
  47. +3 −3 ...erters/src/main/groovy/org/codehaus/groovy/grails/web/converters/marshaller/json/DomainClassMarshaller.java
  48. +1 −1  ...ers/src/main/groovy/org/codehaus/groovy/grails/web/converters/marshaller/xml/DeepDomainClassMarshaller.java
  49. +2 −2 ...verters/src/main/groovy/org/codehaus/groovy/grails/web/converters/marshaller/xml/DomainClassMarshaller.java
  50. +1 −1  ...plugin-domain-class/src/test/groovy/org/codehaus/groovy/grails/domain/CircularBidirectionalMapBySpec.groovy
  51. +1 −1  grails-plugin-domain-class/src/test/groovy/org/codehaus/groovy/grails/plugins/AddToSpec.groovy
  52. +1 −1  ...gin-filters/src/main/groovy/org/codehaus/groovy/grails/plugins/web/filters/DefaultGrailsFiltersClass.groovy
  53. +1 −1  grails-plugin-log4j/src/main/groovy/org/codehaus/groovy/grails/plugins/log4j/web/util/Log4jConfigListener.java
  54. +1 −1  ...ls-plugin-mimetypes/src/test/groovy/org/codehaus/groovy/grails/compiler/web/MimeTypesTransformerSpec.groovy
  55. +1 −1  ...etypes/src/test/groovy/org/codehaus/groovy/grails/plugins/web/api/RequestAndResponseMimeTypesApiSpec.groovy
  56. +1 −1  grails-plugin-mimetypes/src/test/groovy/org/codehaus/groovy/grails/web/mime/AcceptHeaderParserTests.groovy
  57. +1 −1  grails-plugin-mimetypes/src/test/groovy/org/codehaus/groovy/grails/web/mime/MimeUtilitySpec.groovy
  58. +2 −2 grails-plugin-rest/src/main/groovy/grails/rest/render/json/JsonRenderer.groovy
  59. +3 −3 grails-plugin-rest/src/main/groovy/grails/rest/render/util/AbstractLinkingRenderer.groovy
  60. +2 −2 grails-plugin-rest/src/main/groovy/grails/rest/render/xml/XmlRenderer.groovy
  61. +1 −1  grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/api/ControllersRestApi.groovy
  62. +1 −1  grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/DefaultRendererRegistry.groovy
  63. +1 −1  grails-plugin-rest/src/main/groovy/org/grails/plugins/web/rest/render/html/DefaultHtmlRenderer.groovy
  64. +1 −1  grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/VndErrorRenderingSpec.groovy
  65. +1 −3 grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/json/JsonRendererSpec.groovy
  66. +1 −1  grails-plugin-rest/src/test/groovy/org/grails/plugins/web/rest/render/xml/DefaultXmlRendererSpec.groovy
  67. +2 −0  grails-plugin-testing/src/main/groovy/grails/test/GrailsUnitTestCase.groovy
  68. +1 −1  grails-plugin-testing/src/main/groovy/grails/test/MvcUnitTestCase.groovy
  69. +3 −3 grails-plugin-testing/src/main/groovy/grails/test/runtime/CoreBeansTestPlugin.groovy
  70. +1 −1  grails-plugin-testing/src/main/groovy/grails/test/runtime/GrailsApplicationTestPlugin.groovy
  71. +1 −1  grails-project-api/src/main/groovy/org/codehaus/groovy/grails/project/loader/GrailsProjectLoader.groovy
  72. +1 −1  grails-project-api/src/main/groovy/org/codehaus/groovy/grails/project/plugins/GrailsProjectPluginLoader.groovy
  73. +1 −1  grails-scripts/src/main/scripts/Init.groovy
  74. +1 −1  grails-test-suite-base/src/main/groovy/org/codehaus/groovy/grails/commons/test/AbstractGrailsMockTests.java
  75. +1 −1  grails-test-suite-base/src/main/groovy/org/codehaus/groovy/grails/plugins/web/AbstractGrailsPluginTests.groovy
  76. +1 −1  ...-suite-base/src/main/groovy/org/codehaus/groovy/grails/web/servlet/mvc/AbstractGrailsControllerTests.groovy
  77. +1 −1  ...s-test-suite-base/src/main/groovy/org/codehaus/groovy/grails/web/servlet/mvc/MockHibernateProxyHandler.java
  78. +1 −1  grails-test-suite-base/src/main/groovy/org/codehaus/groovy/grails/web/taglib/AbstractGrailsTagTests.groovy
  79. +1 −1  grails-test-suite-persistence/src/test/groovy/org/codehaus/groovy/grails/orm/GormSpec.groovy
  80. +1 −1  grails-test-suite-uber/src/test/groovy/grails/transaction/TransactionalTransformSpec.groovy
  81. +1 −1  grails-test-suite-uber/src/test/groovy/grails/web/JSONBuilderTests.groovy
  82. +2 −0  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/commons/DefaultArtefactInfoTests.groovy
  83. +1 −0  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClassTests.groovy
  84. +1 −0  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/commons/GrailsClassTests.java
  85. +0 −56 ...-uber/src/test/groovy/org/codehaus/groovy/grails/commons/metaclass/ClosureInvokingDynamicMethodTests.groovy
  86. +0 −204 ...suite-uber/src/test/groovy/org/codehaus/groovy/grails/commons/metaclass/DynamicMethodsInterceptorTests.java
  87. +1 −1  ...-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/commons/metaclass/MetaClassEnhancerTests.groovy
  88. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/domain/HeirarchyDomainClassTests.java
  89. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/DefaultGrailsPluginManagerTests.java
  90. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/GrailsPluginTests.groovy
  91. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/PluginFilterTests.java
  92. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/PluginLoadOrderTests.groovy
  93. +1 −1  ...est-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/metadata/GrailsPluginMetadataTests.groovy
  94. +1 −1  ...ite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/testing/GrailsMockHttpServletRequestSpec.groovy
  95. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/web/LoggingGrailsPluginTests.groovy
  96. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/support/DevelopmentResourceLoaderTests.java
  97. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/validation/NullableConstraintTests.groovy
  98. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/context/GrailsConfigUtilsTests.groovy
  99. +1 −1  ...s-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/errors/GrailsExceptionResolverTests.groovy
  100. +1 −1  ...est-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/servlet/GrailsApplicationAttributesTests.java
  101. +1 −1  ...-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/servlet/filter/AbstractServletFilterTests.groovy
  102. +1 −1  ...st-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/sitemesh/GrailsLayoutDecoratorMapperTests.java
  103. +1 −1  grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/util/WebUtilsTests.groovy
  104. +1 −1  ...test-suite-uber/src/test/groovy/org/grails/plugins/web/rest/render/hal/HalDomainClassXmlRendererSpec.groovy
  105. +1 −1  ...-test-suite-uber/src/test/groovy/org/grails/web/servlet/context/support/GrailsRuntimeConfiguratorTests.java
  106. +1 −1  grails-test-suite-web/src/test/groovy/grails/gsp/PageRendererSpec.groovy
  107. +1 −1  grails-test-suite-web/src/test/groovy/grails/rest/web/RespondMethodSpec.groovy
  108. +1 −1  ...ls-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/filters/FilterToHandlerAdapterTests.groovy
  109. +1 −1  grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages/ParseTests.java
  110. +1 −1  grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages/ext/jsp/IterativeJspTagTests.groovy
  111. +1 −1  grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages/ext/jsp/SimpleJspTagTests.groovy
  112. +1 −1  grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages/ext/jsp/SimpleTagTests.groovy
  113. +1 −1  ...-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages/ext/jsp/TagLibraryResolverTests.groovy
  114. +1 −1  grails-web-boot/src/main/groovy/org/grails/boot/support/GrailsApplicationPostProcessor.groovy
  115. +1 −1  grails-web-gsp/src/test/groovy/org/codehaus/groovy/grails/web/pages/TagLibraryLookupSpec.groovy
  116. +1 −1  ...src/test/groovy/org/codehaus/groovy/grails/web/pages/discovery/GrailsConventionGroovyPageLocatorSpec.groovy
  117. +1 −1  grails-web-url-mappings/src/test/groovy/org/codehaus/groovy/grails/web/mapping/LinkGeneratorSpec.groovy
  118. +1 −1  grails-web-url-mappings/src/test/groovy/org/codehaus/groovy/grails/web/mapping/UrlMappingsBindingSpec.groovy
  119. +1 −1  ...rl-mappings/src/test/groovy/org/codehaus/groovy/grails/web/servlet/mvc/UrlMappingsHandlerMappingSpec.groovy
  120. +1 −1  grails-web/src/main/groovy/org/grails/web/servlet/boostrap/DefaultGrailsBootstrapClass.java
View
8 ...ain/groovy/org/codehaus/groovy/grails/resolve/maven/aether/AetherDependencyManager.groovy
@@ -1,8 +0,0 @@
-package org.codehaus.groovy.grails.resolve.maven.aether
-
-/**
- * @author Graeme Rocher
- * @deprecated Use {@link org.grails.resolve.maven.aether.AetherDependencyManager} instead
- */
-class AetherDependencyManager extends org.grails.resolve.maven.aether.AetherDependencyManager{
-}
View
25 ...bility/src/main/groovy/org/codehaus/groovy/grails/support/proxy/EntityProxyHandler.groovy
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2010 the original author or authors.
+ *
+ * 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.codehaus.groovy.grails.support.proxy
+
+/**
+ * @author Graeme Rocher
+ * @deprecated Use {@link grails.core.support.proxy.EntityProxyHandler} instead
+ */
+@Deprecated
+public interface EntityProxyHandler extends ProxyHandler, grails.core.support.proxy.EntityProxyHandler {
+
+}
View
15 ...ils/support/ParticipatingInterceptor.java → .../grails/support/proxy/ProxyHandler.groovy
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 SpringSource
+ * Copyright 2004-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.support;
+package org.codehaus.groovy.grails.support.proxy
-public interface ParticipatingInterceptor extends PersistenceContextInterceptor {
-
- void setParticipate(boolean participate);
-
- boolean getParticipate();
+/**
+ * @author Graeme Rocher
+ * @deprecated Use {@link grails.core.support.proxy.ProxyHandler} instead
+ */
+@Deprecated
+interface ProxyHandler extends grails.core.support.proxy.ProxyHandler{
}
View
4 grails-core/src/main/groovy/grails/config/Settings.groovy
@@ -20,6 +20,10 @@ interface Settings {
*/
String SPRING_PLACEHOLDER_PREFIX = "grails.spring.placeholder.prefix";
+ /**
+ * Whether to include the jsessionid in the rendered links
+ **/
+ String GRAILS_VIEWS_ENABLE_JSESSIONID = "grails.views.enable.jsessionid";
String GSP_DISABLE_CACHING_RESOURCES = "grails.gsp.disable.caching.resources";
String GSP_ENABLE_RELOAD = "grails.gsp.enable.reload";
String CLASS_RESOURCE_PATTERN = "/**/*.class"
View
2  ...ls/commons/AbstractGrailsApplication.java → ...rails/core/AbstractGrailsApplication.java
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
+package grails.core;
import grails.core.ArtefactHandler;
import grails.core.GrailsApplication;
View
5 ...y/grails/commons/AbstractGrailsClass.java → ...oovy/grails/core/AbstractGrailsClass.java
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
+package grails.core;
-import grails.core.GrailsApplication;
-import grails.core.GrailsClass;
import grails.util.GrailsClassUtils;
import grails.util.GrailsMetaClassUtils;
import grails.util.GrailsNameUtils;
@@ -26,6 +24,7 @@
import groovy.lang.MetaClass;
import groovy.lang.MetaProperty;
import grails.exceptions.NewInstanceCreationException;
+import org.codehaus.groovy.grails.commons.ClassPropertyFetcher;
import org.codehaus.groovy.grails.plugins.GrailsVersionUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
View
4 ...ommons/AbstractInjectableGrailsClass.java → ...s/core/AbstractInjectableGrailsClass.java
@@ -13,9 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
-
-import grails.core.InjectableGrailsClass;
+package grails.core;
/**
* Configures Grails classe to be autowirable by name, always.
View
238 ...y/grails/commons/DefaultArtefactInfo.java → ...oovy/grails/core/DefaultArtefactInfo.java
@@ -1,119 +1,119 @@
-/*
- * Copyright 2004-2005 the original author or authors.
- *
- * 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.codehaus.groovy.grails.commons;
-
-import grails.core.ArtefactInfo;
-import grails.core.GrailsClass;
-import grails.core.InjectableGrailsClass;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-
-/**
- * Mutable holder of artefact info.
- *
- * @author Marc Palmer (marc@anyware.co.uk)
- * @author Graeme Rocher
- */
-public class DefaultArtefactInfo implements ArtefactInfo, org.codehaus.groovy.grails.commons.ArtefactInfo {
-
- private LinkedList<GrailsClass> grailsClasses = new LinkedList<GrailsClass>();
- private Class<?>[] classes;
- private Map<String, GrailsClass> grailsClassesByName = new LinkedHashMap<String, GrailsClass>();
- private Map<String, Class<?>> classesByName = new LinkedHashMap<String, Class<?>>();
- private Map<String, GrailsClass> logicalPropertyNameToClassMap = new HashMap<String, GrailsClass>();
- @SuppressWarnings("rawtypes")
- public Map handlerData = new HashMap();
- private GrailsClass[] grailsClassesArray;
-
- /**
- * <p>Call to add a new class to this info object.</p>
- * <p>You <b>must</b> call refresh() later to update the arrays</p>
- * @param artefactClass
- */
- public synchronized void addGrailsClass(GrailsClass artefactClass) {
- addGrailsClassInternal(artefactClass, false);
- }
-
- private void addGrailsClassInternal(GrailsClass artefactClass, boolean atStart) {
- grailsClassesByName = new LinkedHashMap<String, GrailsClass>(grailsClassesByName);
- classesByName = new LinkedHashMap<String, Class<?>>(classesByName);
-
- Class<?> actualClass = artefactClass.getClazz();
- boolean addToGrailsClasses = true;
- if (artefactClass instanceof InjectableGrailsClass) {
- addToGrailsClasses = ((InjectableGrailsClass)artefactClass).getAvailable();
- }
- if (addToGrailsClasses) {
- GrailsClass oldVersion = grailsClassesByName.put(actualClass.getName(), artefactClass);
- grailsClasses.remove(oldVersion);
- }
- classesByName.put(actualClass.getName(), actualClass);
- logicalPropertyNameToClassMap.put(artefactClass.getLogicalPropertyName(), artefactClass);
-
- if (!grailsClasses.contains(artefactClass)) {
- if (atStart) {
- grailsClasses.addFirst(artefactClass);
- }
- else {
- grailsClasses.addLast(artefactClass);
- }
- }
- }
-
- /**
- * Refresh the arrays generated from the maps.
- */
- public synchronized void updateComplete() {
- grailsClassesByName = Collections.unmodifiableMap(grailsClassesByName);
- classesByName = Collections.unmodifiableMap(classesByName);
-
- grailsClassesArray = grailsClasses.toArray(new GrailsClass[grailsClasses.size()]);
- // Make classes array
- classes = classesByName.values().toArray(new Class[classesByName.size()]);
- }
-
- public Class<?>[] getClasses() {
- return classes;
- }
-
- public GrailsClass[] getGrailsClasses() {
- return grailsClassesArray;
- }
-
- public Map<String, Class<?>> getClassesByName() {
- return classesByName;
- }
-
- public Map<String, GrailsClass> getGrailsClassesByName() {
- return grailsClassesByName;
- }
-
- public GrailsClass getGrailsClass(String name) {
- return grailsClassesByName.get(name);
- }
-
- public GrailsClass getGrailsClassByLogicalPropertyName(String logicalName) {
- return logicalPropertyNameToClassMap.get(logicalName);
- }
-
- public void addOverridableGrailsClass(GrailsClass artefactGrailsClass) {
- addGrailsClassInternal(artefactGrailsClass, true);
- }
-}
+/*
+ * Copyright 2004-2005 the original author or authors.
+ *
+ * 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 grails.core;
+
+import grails.core.ArtefactInfo;
+import grails.core.GrailsClass;
+import grails.core.InjectableGrailsClass;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+/**
+ * Mutable holder of artefact info.
+ *
+ * @author Marc Palmer (marc@anyware.co.uk)
+ * @author Graeme Rocher
+ */
+public class DefaultArtefactInfo implements ArtefactInfo, org.codehaus.groovy.grails.commons.ArtefactInfo {
+
+ private LinkedList<GrailsClass> grailsClasses = new LinkedList<GrailsClass>();
+ private Class<?>[] classes;
+ private Map<String, GrailsClass> grailsClassesByName = new LinkedHashMap<String, GrailsClass>();
+ private Map<String, Class<?>> classesByName = new LinkedHashMap<String, Class<?>>();
+ private Map<String, GrailsClass> logicalPropertyNameToClassMap = new HashMap<String, GrailsClass>();
+ @SuppressWarnings("rawtypes")
+ public Map handlerData = new HashMap();
+ private GrailsClass[] grailsClassesArray;
+
+ /**
+ * <p>Call to add a new class to this info object.</p>
+ * <p>You <b>must</b> call refresh() later to update the arrays</p>
+ * @param artefactClass
+ */
+ public synchronized void addGrailsClass(GrailsClass artefactClass) {
+ addGrailsClassInternal(artefactClass, false);
+ }
+
+ private void addGrailsClassInternal(GrailsClass artefactClass, boolean atStart) {
+ grailsClassesByName = new LinkedHashMap<String, GrailsClass>(grailsClassesByName);
+ classesByName = new LinkedHashMap<String, Class<?>>(classesByName);
+
+ Class<?> actualClass = artefactClass.getClazz();
+ boolean addToGrailsClasses = true;
+ if (artefactClass instanceof InjectableGrailsClass) {
+ addToGrailsClasses = ((InjectableGrailsClass)artefactClass).getAvailable();
+ }
+ if (addToGrailsClasses) {
+ GrailsClass oldVersion = grailsClassesByName.put(actualClass.getName(), artefactClass);
+ grailsClasses.remove(oldVersion);
+ }
+ classesByName.put(actualClass.getName(), actualClass);
+ logicalPropertyNameToClassMap.put(artefactClass.getLogicalPropertyName(), artefactClass);
+
+ if (!grailsClasses.contains(artefactClass)) {
+ if (atStart) {
+ grailsClasses.addFirst(artefactClass);
+ }
+ else {
+ grailsClasses.addLast(artefactClass);
+ }
+ }
+ }
+
+ /**
+ * Refresh the arrays generated from the maps.
+ */
+ public synchronized void updateComplete() {
+ grailsClassesByName = Collections.unmodifiableMap(grailsClassesByName);
+ classesByName = Collections.unmodifiableMap(classesByName);
+
+ grailsClassesArray = grailsClasses.toArray(new GrailsClass[grailsClasses.size()]);
+ // Make classes array
+ classes = classesByName.values().toArray(new Class[classesByName.size()]);
+ }
+
+ public Class<?>[] getClasses() {
+ return classes;
+ }
+
+ public GrailsClass[] getGrailsClasses() {
+ return grailsClassesArray;
+ }
+
+ public Map<String, Class<?>> getClassesByName() {
+ return classesByName;
+ }
+
+ public Map<String, GrailsClass> getGrailsClassesByName() {
+ return grailsClassesByName;
+ }
+
+ public GrailsClass getGrailsClass(String name) {
+ return grailsClassesByName.get(name);
+ }
+
+ public GrailsClass getGrailsClassByLogicalPropertyName(String logicalName) {
+ return logicalPropertyNameToClassMap.get(logicalName);
+ }
+
+ public void addOverridableGrailsClass(GrailsClass artefactGrailsClass) {
+ addGrailsClassInternal(artefactGrailsClass, true);
+ }
+}
View
29 ...ils/commons/DefaultGrailsApplication.java → ...grails/core/DefaultGrailsApplication.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
+package grails.core;
import grails.util.Environment;
import grails.util.GrailsNameUtils;
@@ -29,6 +29,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codehaus.groovy.grails.commons.*;
import org.codehaus.groovy.grails.commons.cfg.ConfigurationHelper;
import grails.core.events.ArtefactAdditionEvent;
import org.grails.core.DomainClassArtefactHandler;
@@ -61,7 +62,7 @@
* @see grails.core.ArtefactInfo
* @since 0.1
*/
-public class DefaultGrailsApplication extends AbstractGrailsApplication implements GrailsApplication, BeanClassLoaderAware {
+public class DefaultGrailsApplication extends AbstractGrailsApplication implements org.codehaus.groovy.grails.commons.GrailsApplication, BeanClassLoaderAware {
protected static final Pattern GETCLASSESPROP_PATTERN = Pattern.compile("(\\w+)(Classes)");
protected static final Pattern GETCLASSESMETH_PATTERN = Pattern.compile("(get)(\\w+)(Classes)");
@@ -188,9 +189,9 @@ protected void initArtefactHandlers() {
registerArtefactHandler(urlMappingsArtefactHandler);
}
- List<ArtefactHandler> additionalArtefactHandlers = GrailsFactoriesLoader.loadFactories(ArtefactHandler.class, getClassLoader());
+ List<org.codehaus.groovy.grails.commons.ArtefactHandler> additionalArtefactHandlers = GrailsFactoriesLoader.loadFactories(org.codehaus.groovy.grails.commons.ArtefactHandler.class, getClassLoader());
- for (ArtefactHandler artefactHandler : additionalArtefactHandlers) {
+ for (org.codehaus.groovy.grails.commons.ArtefactHandler artefactHandler : additionalArtefactHandlers) {
registerArtefactHandler(artefactHandler);
}
@@ -200,7 +201,7 @@ protected void initArtefactHandlers() {
private void updateArtefactHandlers() {
// Cache the list as an array
artefactHandlers = artefactHandlersByName.values().toArray(
- new ArtefactHandler[artefactHandlersByName.size()]);
+ new org.codehaus.groovy.grails.commons.ArtefactHandler[artefactHandlersByName.size()]);
}
/**
@@ -300,7 +301,7 @@ public ConfigObject getConfig() {
* @return The number of registered artefacts
*/
protected int getArtefactCount(String artefactType) {
- ArtefactInfo info = getArtefactInfo(artefactType);
+ org.codehaus.groovy.grails.commons.ArtefactInfo info = getArtefactInfo(artefactType);
return info == null ? 0 : info.getClasses().length;
}
@@ -464,11 +465,6 @@ protected GrailsClass getFirstArtefact(String artefactType) {
return getArtefactInfo(artefactType, true).getGrailsClasses();
}
- // This is next call is equiv to getControllerByURI / getTagLibForTagName
- public GrailsClass getArtefactForFeature(String artefactType, Object featureID) {
- return artefactHandlersByName.get(artefactType).getArtefactForFeature(featureID);
- }
-
/**
* Adds an artefact of the given type for the given Class.
*
@@ -520,6 +516,8 @@ public void registerArtefactHandler(ArtefactHandler handler) {
updateArtefactHandlers();
}
+
+
public boolean hasArtefactHandler(String type) {
return artefactHandlersByName.containsKey(type);
}
@@ -561,7 +559,7 @@ protected void initializeArtefacts(ArtefactHandler handler) {
return;
}
- ArtefactInfo info = getArtefactInfo(handler.getType());
+ org.codehaus.groovy.grails.commons.ArtefactInfo info = getArtefactInfo(handler.getType());
// Only init those that have data
if (info != null) {
//System.out.println("Initialising artefacts of kind " + handler.getType() + " with registered artefacts" + info.getGrailsClassesByName());
@@ -592,7 +590,7 @@ protected DefaultArtefactInfo getArtefactInfo(String artefactType, boolean creat
* @param artefactType The name of an artefact type
* @return The cache of classes for the type, or null if no cache exists
*/
- public ArtefactInfo getArtefactInfo(String artefactType) {
+ public org.codehaus.groovy.grails.commons.ArtefactInfo getArtefactInfo(String artefactType) {
return getArtefactInfo(artefactType, false);
}
@@ -688,6 +686,11 @@ public void initialise() {
initialised = true;
}
+ // This is next call is equiv to getControllerByURI / getTagLibForTagName
+ public GrailsClass getArtefactForFeature(String artefactType, Object featureID) {
+ return artefactHandlersByName.get(artefactType).getArtefactForFeature(featureID);
+ }
+
public boolean isInitialised() {
return initialised;
}
View
2  ...vy/grails/commons/DefaultGrailsClass.java → ...roovy/grails/core/DefaultGrailsClass.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
+package grails.core;
/**
* A default implementation for Grails classes that need to be registered and managed by a GrailsApplication,
View
3  .../commons/StandaloneGrailsApplication.java → ...ils/core/StandaloneGrailsApplication.java
@@ -12,8 +12,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons;
+package grails.core;
+import grails.core.AbstractGrailsApplication;
import grails.core.ArtefactHandler;
import grails.core.ArtefactInfo;
import grails.core.GrailsClass;
View
2  ...ls/support/proxy/DefaultProxyHandler.java → ...re/support/proxy/DefaultProxyHandler.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.support.proxy;
+package grails.core.support.proxy;
/**
* Trivial default implementation that always returns true and the object.
View
2  ...ils/support/proxy/EntityProxyHandler.java → ...ore/support/proxy/EntityProxyHandler.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.support.proxy;
+package grails.core.support.proxy;
/**
* Methods specified to proxied entities
View
2  ...vy/grails/support/proxy/ProxyHandler.java → ...ails/core/support/proxy/ProxyHandler.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.support.proxy;
+package grails.core.support.proxy;
/**
* Interface that defines logic for handling proxied instances
View
1  ...ls-core/src/main/groovy/org/codehaus/groovy/grails/commons/ControllerArtefactHandler.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractGrailsClass;
import grails.core.ArtefactHandlerAdapter;
import grails.core.GrailsClass;
import grails.core.GrailsControllerClass;
View
1  ...core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsControllerClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractInjectableGrailsClass;
import grails.core.GrailsControllerClass;
import grails.web.Action;
import groovy.lang.GroovyObject;
View
3  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractGrailsClass;
import grails.core.ComponentCapableDomainClass;
import grails.core.GrailsDomainClass;
import grails.core.GrailsDomainClassProperty;
@@ -701,7 +702,7 @@ public String getFieldName(String propertyName) {
}
/* (non-Javadoc)
- * @see org.codehaus.groovy.grails.commons.AbstractGrailsClass#getName()
+ * @see grails.core.AbstractGrailsClass#getName()
*/
@Override
public String getName() {
View
1  .../src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClassProperty.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractGrailsClass;
import grails.core.ComponentCapableDomainClass;
import grails.core.GrailsDomainClass;
import grails.core.GrailsDomainClassProperty;
View
1  ...ls-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsServiceClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractInjectableGrailsClass;
import grails.core.GrailsServiceClass;
/**
View
1  grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsTagLibClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractInjectableGrailsClass;
import grails.core.GrailsTagLibClass;
import groovy.lang.Closure;
View
1  ...ore/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsUrlMappingsClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractGrailsClass;
import grails.core.GrailsUrlMappingsClass;
import groovy.lang.Closure;
View
2  grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/AbstractGrailsPlugin.java
@@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;
-import org.codehaus.groovy.grails.commons.AbstractGrailsClass;
+import grails.core.AbstractGrailsClass;
import grails.core.GrailsApplication;
import org.codehaus.groovy.grails.plugins.support.WatchPattern;
import org.springframework.beans.BeansException;
View
8 grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/CoreGrailsPlugin.groovy
@@ -24,8 +24,8 @@ import grails.util.GrailsUtil
import org.grails.spring.aop.autoproxy.GroovyAwareAspectJAwareAdvisorAutoProxyCreator
import org.grails.spring.aop.autoproxy.GroovyAwareInfrastructureAdvisorAutoProxyCreator
import grails.core.GrailsApplication
-import org.codehaus.groovy.grails.commons.cfg.GrailsPlaceholderConfigurer
-import org.codehaus.groovy.grails.commons.cfg.MapBasedSmartPropertyOverrideConfigurer
+import org.grails.spring.context.support.GrailsPlaceholderConfigurer
+import org.grails.spring.context.support.MapBasedSmartPropertyOverrideConfigurer
import org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration
import org.grails.spring.beans.factory.OptimizedAutowireCapableBeanFactory
import org.grails.spring.RuntimeSpringConfigUtilities
@@ -36,8 +36,8 @@ import org.grails.plugins.support.GrailsApplicationAwareBeanPostProcessor
import org.grails.plugins.support.PluginManagerAwareBeanPostProcessor
import org.codehaus.groovy.grails.support.ClassEditor
import org.codehaus.groovy.grails.support.DevelopmentShutdownHook
-import org.codehaus.groovy.grails.support.PropertiesEditor
-import org.codehaus.groovy.grails.support.proxy.DefaultProxyHandler
+import org.grails.beans.support.PropertiesEditor
+import grails.core.support.proxy.DefaultProxyHandler
import org.springframework.beans.factory.config.CustomEditorConfigurer
import org.springframework.beans.factory.config.MethodInvokingFactoryBean
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader
View
2  grails-core/src/main/groovy/org/codehaus/groovy/grails/plugins/MockGrailsPluginManager.java
@@ -24,7 +24,7 @@
import java.util.Map;
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication;
+import grails.core.DefaultGrailsApplication;
import grails.core.GrailsApplication;
import org.codehaus.groovy.grails.plugins.exceptions.PluginException;
import org.springframework.util.Assert;
View
2  ...oovy/grails/support/PropertiesEditor.java → ...rails/beans/support/PropertiesEditor.java
@@ -1,4 +1,4 @@
-package org.codehaus.groovy.grails.support;
+package org.grails.beans.support;
import java.util.Map;
import java.util.Properties;
View
2  grails-core/src/main/groovy/org/grails/core/support/GrailsApplicationFactoryBean.java
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication;
+import grails.core.DefaultGrailsApplication;
import org.codehaus.groovy.grails.io.support.IOUtils;
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils;
import org.springframework.beans.factory.FactoryBean;
View
2  ...mons/cfg/GrailsPlaceholderConfigurer.java → .../support/GrailsPlaceholderConfigurer.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons.cfg;
+package org.grails.spring.context.support;
import grails.config.GrailsConfig;
import groovy.util.ConfigObject;
View
2  ...sedSmartPropertyOverrideConfigurer.groovy → ...sedSmartPropertyOverrideConfigurer.groovy
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.codehaus.groovy.grails.commons.cfg
+package org.grails.spring.context.support
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
View
2  ...odehaus/groovy/grails/commons/cfg/GrailsPlaceHolderConfigurerCorePluginRuntimeSpec.groovy
@@ -1,7 +1,7 @@
package org.codehaus.groovy.grails.commons.cfg
import grails.spring.BeanBuilder
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import grails.core.DefaultGrailsApplication
import org.codehaus.groovy.grails.plugins.CoreGrailsPlugin
import spock.lang.Issue
import spock.lang.Specification
View
3  ...test/groovy/org/codehaus/groovy/grails/commons/cfg/GrailsPlaceholderConfigurerSpec.groovy
@@ -2,7 +2,8 @@ package org.codehaus.groovy.grails.commons.cfg
import grails.spring.BeanBuilder
import grails.util.Holders
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import grails.core.DefaultGrailsApplication
+import org.grails.spring.context.support.GrailsPlaceholderConfigurer
import spock.lang.Issue
import spock.lang.Specification
View
2  ...codehaus/groovy/grails/context/support/PluginAwareResourceBundleMessageSourceTests.groovy
@@ -1,6 +1,6 @@
package org.codehaus.groovy.grails.context.support
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import grails.core.DefaultGrailsApplication
import org.codehaus.groovy.grails.plugins.DefaultGrailsPluginManager
import org.codehaus.groovy.grails.plugins.GrailsPlugin
import org.codehaus.groovy.grails.support.MockFileResource
View
2  grails-core/src/test/groovy/org/codehaus/groovy/grails/core/io/ResourceLocatorSpec.groovy
@@ -1,6 +1,6 @@
package org.codehaus.groovy.grails.core.io
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import grails.core.DefaultGrailsApplication
import org.codehaus.groovy.grails.plugins.BinaryGrailsPlugin
import org.codehaus.groovy.grails.plugins.BinaryGrailsPluginDescriptor
import org.codehaus.groovy.grails.plugins.MockBinaryPluginResource
View
2  grails-core/src/test/groovy/org/codehaus/groovy/grails/plugins/BinaryPluginSpec.groovy
@@ -1,6 +1,6 @@
package org.codehaus.groovy.grails.plugins
-import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import grails.core.DefaultGrailsApplication
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
View
1  ...in-codecs/src/main/groovy/org/codehaus/groovy/grails/commons/DefaultGrailsCodecClass.java
@@ -15,6 +15,7 @@
*/
package org.codehaus.groovy.grails.commons;
+import grails.core.AbstractInjectableGrailsClass;
import groovy.lang.Closure;
import java.io.IOException;
View
4 ...ers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/ControllersGrailsPlugin.groovy
@@ -16,6 +16,7 @@
package org.codehaus.groovy.grails.plugins.web
import grails.artefact.Enhanced
+import grails.config.Settings
import grails.util.Environment
import grails.util.GrailsUtil
import grails.util.GrailsWebUtil
@@ -31,7 +32,6 @@ import org.codehaus.groovy.grails.plugins.web.api.ControllersApi
import org.codehaus.groovy.grails.plugins.web.api.ControllersDomainBindingApi
import org.grails.web.errors.GrailsExceptionResolver
import org.grails.web.filters.HiddenHttpMethodFilter
-import org.codehaus.groovy.grails.web.metaclass.RedirectDynamicMethod
import org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter
import org.grails.web.servlet.mvc.GrailsDispatcherServlet
import org.grails.web.servlet.mvc.GrailsWebRequestFilter
@@ -140,7 +140,7 @@ class ControllersGrailsPlugin implements ServletContextInitializer, GrailsApplic
def redirectListeners = ctx.getBeansOfType(RedirectEventListener)
controllerApi.setRedirectListeners(redirectListeners.values())
- Object o = application.getFlatConfig().get(RedirectDynamicMethod.GRAILS_VIEWS_ENABLE_JSESSIONID)
+ Object o = application.getFlatConfig().get(Settings.GRAILS_VIEWS_ENABLE_JSESSIONID)
if (o instanceof Boolean) {
controllerApi.setUseJessionId(o)
}
View
708 ...ontrollers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java
@@ -15,14 +15,20 @@
*/
package org.codehaus.groovy.grails.plugins.web.api;
+import grails.async.Promise;
+import grails.converters.JSON;
+import grails.core.GrailsControllerClass;
import grails.databinding.CollectionDataBindingSource;
import grails.databinding.DataBindingSource;
-import grails.util.CollectionUtils;
-import grails.util.Environment;
-import grails.util.GrailsNameUtils;
-import groovy.lang.Closure;
-import groovy.lang.GroovyObject;
+import grails.util.*;
+import grails.web.JSONBuilder;
+import grails.web.http.HttpHeaders;
+import grails.web.mapping.ResponseRedirector;
+import grails.web.mime.MimeType;
+import grails.web.mime.MimeUtility;
+import groovy.lang.*;
+import java.io.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
@@ -35,28 +41,41 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import groovy.text.Template;
+import groovy.util.slurpersupport.GPathResult;
+import groovy.xml.StreamingMarkupBuilder;
import org.codehaus.groovy.grails.commons.ControllerArtefactHandler;
+import org.codehaus.groovy.grails.io.support.GrailsIOUtils;
+import org.codehaus.groovy.grails.io.support.GrailsResourceUtils;
+import org.codehaus.groovy.grails.io.support.IOUtils;
+import org.codehaus.groovy.grails.plugins.GrailsPlugin;
+import org.codehaus.groovy.grails.web.converters.Converter;
+import org.codehaus.groovy.grails.web.json.JSONElement;
+import org.codehaus.groovy.grails.web.metaclass.*;
+import org.codehaus.groovy.grails.web.pages.GroovyPageTemplate;
+import org.codehaus.groovy.grails.web.servlet.view.GroovyPageView;
+import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper;
+import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutView;
+import org.codehaus.groovy.grails.web.sitemesh.GroovyPageLayoutFinder;
import org.grails.core.DomainClassArtefactHandler;
-import grails.util.GrailsClassUtils;
import grails.core.GrailsDomainClassProperty;
import org.codehaus.groovy.grails.compiler.web.ControllerActionTransformer;
import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
import org.codehaus.groovy.grails.web.binding.DataBindingUtils;
import org.codehaus.groovy.grails.web.controllers.ControllerExceptionHandlerMetaData;
import grails.web.mapping.LinkGenerator;
-import org.codehaus.groovy.grails.web.metaclass.ChainMethod;
-import org.codehaus.groovy.grails.web.metaclass.ForwardMethod;
-import org.codehaus.groovy.grails.web.metaclass.RedirectDynamicMethod;
-import org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod;
-import org.codehaus.groovy.grails.web.metaclass.WithFormMethod;
import org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils;
import grails.web.util.GrailsApplicationAttributes;
+import org.grails.web.servlet.mvc.ActionResultTransformer;
import org.grails.web.servlet.mvc.GrailsWebRequest;
import grails.web.mapping.mvc.RedirectEventListener;
import grails.web.mapping.mvc.exceptions.CannotRedirectException;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.grails.web.api.CommonWebApi;
+import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException;
+import org.grails.web.support.ResourceAwareTemplateEngine;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpMethod;
@@ -65,7 +84,9 @@
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.servlet.ModelAndView;
-
+import org.springframework.web.servlet.View;
+import org.springframework.web.servlet.support.RequestDataValueProcessor;
+import static org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod.*;
/**
* API for each controller in a Grails application.
*
@@ -83,10 +104,16 @@
protected static final String RENDER_METHOD_NAME = "render";
protected static final String BIND_DATA_METHOD = "bindData";
protected static final String SLASH = "/";
- protected transient RedirectDynamicMethod redirect;
protected transient RenderDynamicMethod render;
protected transient WithFormMethod withFormMethod;
protected transient ForwardMethod forwardMethod;
+ private Collection<RedirectEventListener> redirectListeners;
+ private LinkGenerator linkGenerator;
+ private RequestDataValueProcessor requestDataValueProcessor;
+ private boolean useJessionId = false;
+ private MimeUtility mimeUtility;
+ private Collection<ActionResultTransformer> actionResultTransformers;
+ private String gspEncoding = DEFAULT_ENCODING;
public ControllersApi() {
this(null);
@@ -94,7 +121,6 @@ public ControllersApi() {
public ControllersApi(GrailsPluginManager pluginManager) {
super(pluginManager);
- redirect = new RedirectDynamicMethod();
render = new RenderDynamicMethod();
withFormMethod = new WithFormMethod();
forwardMethod = new ForwardMethod();
@@ -109,19 +135,19 @@ public static ApplicationContext getStaticApplicationContext() {
}
public void setGspEncoding(String gspEncoding) {
- render.setGspEncoding(gspEncoding);
+ this.gspEncoding = gspEncoding;
}
public void setRedirectListeners(Collection<RedirectEventListener> redirectListeners) {
- redirect.setRedirectListeners(redirectListeners);
+ this.redirectListeners = redirectListeners;
}
public void setUseJessionId(boolean useJessionId) {
- redirect.setUseJessionId(useJessionId);
+ this.useJessionId = useJessionId;
}
public void setLinkGenerator(LinkGenerator linkGenerator) {
- redirect.setLinkGenerator(linkGenerator);
+ this.linkGenerator = linkGenerator;
}
/**
@@ -241,11 +267,45 @@ public boolean hasErrors(Object instance) {
/**
* Redirects for the given arguments.
*
- * @param args The arguments
+ * @param argMap The arguments
* @return null
*/
- public Object redirect(Object instance,Map args) {
- return redirect.invoke(instance, "redirect", new Object[]{ args });
+ public Object redirect(Object target, Map argMap) {
+
+ if (argMap.isEmpty()) {
+ throw new MissingMethodException("redirect",target.getClass(),new Object[]{ argMap });
+ }
+
+ GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
+
+ if(target instanceof GroovyObject) {
+ GroovyObject controller = (GroovyObject)target;
+
+ // if there are errors add it to the list of errors
+ Errors controllerErrors = (Errors)controller.getProperty(ControllerDynamicMethods.ERRORS_PROPERTY);
+ Errors errors = (Errors)argMap.get(ControllerDynamicMethods.ERRORS_PROPERTY);
+ if (controllerErrors != null && errors != null) {
+ controllerErrors.addAllErrors(errors);
+ }
+ else {
+ controller.setProperty(ControllerDynamicMethods.ERRORS_PROPERTY, errors);
+ }
+ Object action = argMap.get(GrailsControllerClass.ACTION);
+ if (action != null) {
+ argMap.put(GrailsControllerClass.ACTION, establishActionName(action,controller));
+ }
+ if (!argMap.containsKey(GrailsControllerClass.NAMESPACE_PROPERTY)) {
+ // this could be made more efficient if we had a reference to the GrailsControllerClass object, which
+ // has the namespace property accessible without needing reflection
+ argMap.put(GrailsControllerClass.NAMESPACE_PROPERTY, GrailsClassUtils.getStaticFieldValue(controller.getClass(), GrailsControllerClass.NAMESPACE_PROPERTY));
+ }
+ }
+
+ ResponseRedirector redirector = new ResponseRedirector(getLinkGenerator(webRequest));
+ redirector.setRedirectListeners(redirectListeners);
+ redirector.setRequestDataValueProcessor(initRequestDataValueProcessor());
+ redirector.setUseJessionId(useJessionId);
+ return null;
}
/**
@@ -306,8 +366,178 @@ public Object render(Object instance, Map args, Closure c) {
return invokeRender(instance, args, c);
}
- protected Object invokeRender(Object instance, Object... args) {
- return render.invoke(instance, RENDER_METHOD_NAME, args);
+ protected Object invokeRender(Object target, Object... arguments) {
+ if (arguments.length == 0) {
+ throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments);
+ }
+
+ GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.currentRequestAttributes();
+ HttpServletResponse response = webRequest.getCurrentResponse();
+
+ boolean renderView = true;
+ GroovyObject controller = (GroovyObject) target;
+
+ String explicitSiteMeshLayout = null;
+
+ final Object renderArgument = arguments[0];
+ if (renderArgument instanceof Converter<?>) {
+ renderView = renderConverter((Converter<?>)renderArgument, response);
+ } else if (renderArgument instanceof Writable) {
+ applyContentType(response, null, renderArgument);
+ Writable writable = (Writable)renderArgument;
+ renderView = renderWritable(writable, response);
+ } else if (renderArgument instanceof CharSequence) {
+ applyContentType(response, null, renderArgument);
+ CharSequence text = (CharSequence)renderArgument;
+ renderView = renderText(text, response);
+ }
+ else {
+ final Object renderObject = arguments[arguments.length - 1];
+ if (renderArgument instanceof Closure) {
+ setContentType(response, TEXT_HTML, DEFAULT_ENCODING, true);
+ Closure closure = (Closure) renderObject;
+ renderView = renderMarkup(closure, response);
+ }
+ else if (renderArgument instanceof Map) {
+ Map argMap = (Map) renderArgument;
+
+ if (argMap.containsKey(ARGUMENT_LAYOUT)) {
+ explicitSiteMeshLayout = String.valueOf(argMap.get(ARGUMENT_LAYOUT));
+ }
+
+ boolean statusSet = false;
+ if (argMap.containsKey(ARGUMENT_STATUS)) {
+ Object statusObj = argMap.get(ARGUMENT_STATUS);
+ if (statusObj != null) {
+ try {
+ final int statusCode = statusObj instanceof Number ? ((Number)statusObj).intValue() : Integer.parseInt(statusObj.toString());
+ response.setStatus(statusCode);
+ statusSet = true;
+ }
+ catch (NumberFormatException e) {
+ throw new ControllerExecutionException(
+ "Argument [status] of method [render] must be a valid integer.");
+ }
+ }
+ }
+
+ if (renderObject instanceof Writable) {
+ Writable writable = (Writable) renderObject;
+ applyContentType(response, argMap, renderObject);
+ renderView = renderWritable(writable, response);
+ }
+ else if (renderObject instanceof Closure) {
+ Closure callable = (Closure) renderObject;
+ applyContentType(response, argMap, renderObject);
+ if (BUILDER_TYPE_JSON.equals(argMap.get(ARGUMENT_BUILDER)) || isJSONResponse(response)) {
+ renderView = renderJSON(callable, response);
+ }
+ else {
+ renderView = renderMarkup(callable, response);
+ }
+ }
+ else if (renderObject instanceof CharSequence) {
+ applyContentType(response, argMap, renderObject);
+ CharSequence text = (CharSequence) renderObject;
+ renderView = renderText(text, response);
+ }
+ else if (argMap.containsKey(ARGUMENT_TEXT)) {
+ Object textArg = argMap.get(ARGUMENT_TEXT);
+ applyContentType(response, argMap, textArg);
+ if (textArg instanceof Writable) {
+ Writable writable = (Writable) textArg;
+ renderView = renderWritable(writable, response);
+ } else {
+ CharSequence text = (textArg instanceof CharSequence) ? ((CharSequence)textArg) : textArg.toString();
+ renderView = renderText(text, response);
+ }
+ }
+ else if (argMap.containsKey(ARGUMENT_VIEW)) {
+ renderView(webRequest, argMap, target, controller);
+ }
+ else if (argMap.containsKey(ARGUMENT_TEMPLATE)) {
+ applyContentType(response, argMap, null, false);
+ renderView = renderTemplate(target, controller, webRequest, argMap, explicitSiteMeshLayout);
+ }
+ else if (argMap.containsKey(ARGUMENT_FILE)) {
+ renderView = false;
+
+ Object o = argMap.get(ARGUMENT_FILE);
+ Object fnO = argMap.get(ARGUMENT_FILE_NAME);
+ String fileName = fnO != null ? fnO.toString() : ((o instanceof File) ? ((File)o).getName(): null );
+ if (o != null) {
+ boolean hasContentType = applyContentType(response, argMap, null, false);
+ if (fileName != null) {
+ if(!hasContentType) {
+ hasContentType = detectContentTypeFromFileName(webRequest, response, argMap, fileName);
+ }
+ if (fnO != null) {
+ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, DISPOSITION_HEADER_PREFIX + fileName);
+ }
+ }
+ if (!hasContentType) {
+ throw new ControllerExecutionException(
+ "Argument [file] of render method specified without valid [contentType] argument");
+ }
+
+ InputStream input = null;
+ try {
+ if (o instanceof File) {
+ File f = (File) o;
+ input = GrailsIOUtils.openStream(f);
+ }
+ else if (o instanceof InputStream) {
+ input = (InputStream) o;
+ }
+ else if (o instanceof byte[]) {
+ input = new ByteArrayInputStream((byte[])o);
+ }
+ else {
+ input = GrailsIOUtils.openStream(new File(o.toString()));
+ }
+ IOUtils.copy(input, response.getOutputStream());
+ } catch (IOException e) {
+ throw new ControllerExecutionException(
+ "I/O error copying file to response: " + e.getMessage(), e);
+
+ }
+ finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ else if (statusSet) {
+ // GRAILS-6711 nothing to render, just setting status code, so don't render the map
+ renderView = false;
+ }
+ else {
+ Object object = renderArgument;
+ if (object instanceof JSONElement) {
+ renderView = renderJSON((JSONElement)object, response);
+ }
+ else{
+ try {
+ renderView = renderObject(object, response.getWriter());
+ }
+ catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ else {
+ throw new MissingMethodException(METHOD_SIGNATURE, target.getClass(), arguments);
+ }
+ }
+ applySiteMeshLayout(webRequest.getCurrentRequest(), renderView, explicitSiteMeshLayout);
+ webRequest.setRenderView(renderView);
+ return null;
}
public Object bindData(Object instance, Object target, Object bindingSource, final List excludes) {
@@ -345,16 +575,6 @@ public Object bindData(Object instance, Object target, Object bindingSource, Map
DataBindingUtils.bindToCollection(targetType, collectionToPopulate, collectionBindingSource);
}
- @SuppressWarnings("unchecked")
- private List convertToListIfString(Object o) {
- if (o instanceof String) {
- List list = new ArrayList();
- list.add(o);
- o = list;
- }
- return (List) o;
- }
-
/**
* Sets a response header for the given name and value
*
@@ -431,12 +651,12 @@ public Object initializeCommandObject(final Object controllerInstance, final Cla
entityIdentifierValue = null;
}
}
-
+
final HttpMethod requestMethod = HttpMethod.valueOf(request.getMethod());
-
+
if(entityIdentifierValue != null) {
commandObjectInstance = InvokerHelper.invokeStaticMethod(type, "get", entityIdentifierValue);
- } else if(requestMethod == HttpMethod.POST || !isDomainClass){
+ } else if(requestMethod == HttpMethod.POST || !isDomainClass){
commandObjectInstance = type.newInstance();
}
@@ -502,4 +722,420 @@ public Object call(Object object) {
return handlerMethod;
}
+
+ private LinkGenerator getLinkGenerator(GrailsWebRequest webRequest) {
+ if (linkGenerator == null) {
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ if (applicationContext != null) {
+ linkGenerator = applicationContext.getBean("grailsLinkGenerator", LinkGenerator.class);
+ }
+ }
+
+ return linkGenerator;
+ }
+
+ /*
+ * Figures out the action name from the specified action reference (either a string or closure)
+ */
+ private String establishActionName(Object actionRef, Object target) {
+ String actionName = null;
+ if (actionRef instanceof String) {
+ actionName = (String)actionRef;
+ }
+ else if (actionRef instanceof CharSequence) {
+ actionName = actionRef.toString();
+ }
+ else if (actionRef instanceof Closure) {
+ GrailsUtil.deprecated("Using a closure reference in the 'action' argument of the 'redirect' method is deprecated. Please change to use a String.");
+ actionName = GrailsClassUtils.findPropertyNameForValue(target, actionRef);
+ }
+ return actionName;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private List convertToListIfString(Object o) {
+ if (o instanceof String) {
+ List list = new ArrayList();
+ list.add(o);
+ o = list;
+ }
+ return (List) o;
+ }
+
+
+
+ /**
+ * getter to obtain RequestDataValueProcessor from
+ */
+ private RequestDataValueProcessor initRequestDataValueProcessor() {
+ GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ if (requestDataValueProcessor == null && applicationContext.containsBean("requestDataValueProcessor")) {
+ requestDataValueProcessor = applicationContext.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
+ }
+ return requestDataValueProcessor;
+ }
+
+ private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) {
+ if(explicitSiteMeshLayout == null && request.getAttribute(GrailsLayoutDecoratorMapper.LAYOUT_ATTRIBUTE) != null) {
+ // layout has been set already
+ return;
+ }
+ String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : GrailsLayoutDecoratorMapper.NONE_LAYOUT);
+ if(siteMeshLayout != null) {
+ request.setAttribute(GrailsLayoutDecoratorMapper.LAYOUT_ATTRIBUTE, siteMeshLayout);
+ }
+ }
+
+ private boolean renderConverter(Converter<?> converter, HttpServletResponse response) {
+ converter.render(response);
+ return false;
+ }
+
+ private String resolveContentTypeBySourceType(final Object renderArgument, String defaultEncoding) {
+ return renderArgument instanceof GPathResult ? APPLICATION_XML : defaultEncoding;
+ }
+
+ private boolean applyContentType(HttpServletResponse response, Map argMap, Object renderArgument) {
+ return applyContentType(response, argMap, renderArgument, true);
+ }
+
+ private boolean applyContentType(HttpServletResponse response, Map argMap, Object renderArgument, boolean useDefault) {
+ boolean contentTypeIsDefault = true;
+ String contentType = resolveContentTypeBySourceType(renderArgument, useDefault ? TEXT_HTML : null);
+ String encoding = DEFAULT_ENCODING;
+ if (argMap != null) {
+ if(argMap.containsKey(ARGUMENT_CONTENT_TYPE)) {
+ contentType = argMap.get(ARGUMENT_CONTENT_TYPE).toString();
+ contentTypeIsDefault = false;
+ }
+ if(argMap.containsKey(ARGUMENT_ENCODING)) {
+ encoding = argMap.get(ARGUMENT_ENCODING).toString();
+ contentTypeIsDefault = false;
+ }
+ }
+ if(contentType != null) {
+ setContentType(response, contentType, encoding, contentTypeIsDefault);
+ return true;
+ }
+ return false;
+ }
+
+ private boolean renderJSON(JSONElement object, HttpServletResponse response) {
+ response.setContentType(GrailsWebUtil.getContentType("application/json", DEFAULT_ENCODING));
+ return renderWritable(object, response);
+ }
+
+ private boolean detectContentTypeFromFileName(GrailsWebRequest webRequest, HttpServletResponse response, Map argMap, String fileName) {
+ MimeUtility mimeUtility = lookupMimeUtility(webRequest);
+ if (mimeUtility != null) {
+ MimeType mimeType = mimeUtility.getMimeTypeForExtension(GrailsStringUtils.getFilenameExtension(fileName));
+ if (mimeType != null) {
+ String contentType = mimeType.getName();
+ Object encodingObj = argMap.get(ARGUMENT_ENCODING);
+ String encoding = encodingObj != null ? encodingObj.toString() : DEFAULT_ENCODING;
+ setContentType(response, contentType, encoding);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private MimeUtility lookupMimeUtility(GrailsWebRequest webRequest) {
+ if (mimeUtility == null) {
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ if (applicationContext != null) {
+ mimeUtility = applicationContext.getBean("grailsMimeUtility", MimeUtility.class);
+ }
+ }
+ return mimeUtility;
+ }
+
+ private boolean renderTemplate(Object target, GroovyObject controller, GrailsWebRequest webRequest,
+ Map argMap, String explicitSiteMeshLayout) {
+ boolean renderView;
+ boolean hasModel = argMap.containsKey(ARGUMENT_MODEL);
+ Object modelObject = null;
+ if(hasModel) {
+ modelObject = argMap.get(ARGUMENT_MODEL);
+ }
+ String templateName = argMap.get(ARGUMENT_TEMPLATE).toString();
+ String contextPath = getContextPath(webRequest, argMap);
+
+ String var = null;
+ if (argMap.containsKey(ARGUMENT_VAR)) {
+ var = String.valueOf(argMap.get(ARGUMENT_VAR));
+ }
+
+ // get the template uri
+ String templateUri = webRequest.getAttributes().getTemplateURI(controller, templateName);
+
+ // retrieve gsp engine
+ ResourceAwareTemplateEngine engine = webRequest.getAttributes().getPagesTemplateEngine();
+ try {
+ Template t = engine.createTemplateForUri(new String[]{
+ GrailsResourceUtils.appendPiecesForUri(contextPath, templateUri),
+ GrailsResourceUtils.appendPiecesForUri(contextPath, "/grails-app/views/", templateUri)});
+
+ if (t == null) {
+ throw new ControllerExecutionException("Unable to load template for uri [" +
+ templateUri + "]. Template not found.");
+ }
+
+ if (t instanceof GroovyPageTemplate) {
+ ((GroovyPageTemplate)t).setAllowSettingContentType(true);
+ }
+
+ GroovyPageView gspView = new GroovyPageView();
+ gspView.setTemplate(t);
+ try {
+ gspView.afterPropertiesSet();
+ } catch (Exception e) {
+ throw new RuntimeException("Problem initializing view", e);
+ }
+
+ View view = gspView;
+ boolean renderWithLayout = (explicitSiteMeshLayout != null || webRequest.getCurrentRequest().getAttribute(GrailsLayoutDecoratorMapper.LAYOUT_ATTRIBUTE) != null);
+ if(renderWithLayout) {
+ applySiteMeshLayout(webRequest.getCurrentRequest(), false, explicitSiteMeshLayout);
+ try {
+ GroovyPageLayoutFinder groovyPageLayoutFinder = webRequest.getApplicationContext().getBean("groovyPageLayoutFinder", GroovyPageLayoutFinder.class);
+ view = new GrailsLayoutView(groovyPageLayoutFinder, gspView);
+ } catch (NoSuchBeanDefinitionException e) {
+ // ignore
+ }
+ }
+
+ Map binding = new HashMap();
+
+ if (argMap.containsKey(ARGUMENT_BEAN)) {
+ Object bean = argMap.get(ARGUMENT_BEAN);
+ if (hasModel) {
+ if (modelObject instanceof Map) {
+ setTemplateModel(webRequest, binding, (Map) modelObject);
+ }
+ }
+ renderTemplateForBean(webRequest, view, binding, bean, var);
+ }
+ else if (argMap.containsKey(ARGUMENT_COLLECTION)) {
+ Object colObject = argMap.get(ARGUMENT_COLLECTION);
+ if (hasModel) {
+ if (modelObject instanceof Map) {
+ setTemplateModel(webRequest, binding, (Map)modelObject);
+ }
+ }
+ renderTemplateForCollection(webRequest, view, binding, colObject, var);
+ }
+ else if (hasModel) {
+ if (modelObject instanceof Map) {
+ setTemplateModel(webRequest, binding, (Map)modelObject);
+ }
+ renderViewForTemplate(webRequest, view, binding);
+ }
+ else {
+ renderViewForTemplate(webRequest, view, binding);
+ }
+ renderView = false;
+ }
+ catch (GroovyRuntimeException gre) {
+ throw new ControllerExecutionException("Error rendering template [" + templateName + "]: " + gre.getMessage(), gre);
+ }
+ catch (IOException ioex) {
+ throw new ControllerExecutionException("I/O error executing render method for arguments [" + argMap + "]: " + ioex.getMessage(), ioex);
+ }
+ return renderView;
+ }
+
+ protected void renderViewForTemplate(GrailsWebRequest webRequest, View view, Map binding) {
+ try {
+ view.render(binding, webRequest.getCurrentRequest(), webRequest.getResponse());
+ }
+ catch (Exception e) {
+ throw new ControllerExecutionException(e.getMessage(), e);
+ }
+ }
+
+ protected Collection<ActionResultTransformer> getActionResultTransformers(GrailsWebRequest webRequest) {
+ if (actionResultTransformers == null) {
+
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ if (applicationContext != null) {
+ actionResultTransformers = applicationContext.getBeansOfType(ActionResultTransformer.class).values();
+ }
+ if (actionResultTransformers == null) {
+ actionResultTransformers = Collections.emptyList();
+ }
+ }
+
+ return actionResultTransformers;
+ }
+
+ private void setTemplateModel(GrailsWebRequest webRequest, Map binding, Map modelObject) {
+ Map modelMap = modelObject;
+ webRequest.setAttribute(GrailsApplicationAttributes.TEMPLATE_MODEL, modelMap, RequestAttributes.SCOPE_REQUEST);
+ binding.putAll(modelMap);
+ }
+
+ private String getContextPath(GrailsWebRequest webRequest, Map argMap) {
+ Object cp = argMap.get(ARGUMENT_CONTEXTPATH);
+ String contextPath = (cp != null ? cp.toString() : "");
+
+ Object pluginName = argMap.get(ARGUMENT_PLUGIN);
+ if (pluginName != null) {
+ ApplicationContext applicationContext = webRequest.getApplicationContext();
+ GrailsPluginManager pluginManager = (GrailsPluginManager) applicationContext.getBean(GrailsPluginManager.BEAN_NAME);
+ GrailsPlugin plugin = pluginManager.getGrailsPlugin(pluginName.toString());
+ if (plugin != null && !plugin.isBasePlugin()) contextPath = plugin.getPluginPath();
+ }
+ return contextPath;
+ }
+
+ private void setContentType(HttpServletResponse response, String contentType, String encoding) {
+ setContentType(response, contentType, encoding, false);
+ }
+
+ private void setContentType(HttpServletResponse response, String contentType, String encoding, boolean contentTypeIsDefault) {
+ if (!contentTypeIsDefault || response.getContentType()==null) {
+ response.setContentType(GrailsWebUtil.getContentType(contentType, encoding));
+ }
+ }
+
+ private boolean renderObject(Object object, Writer out) {
+ boolean renderView;
+ try {
+ out.write(DefaultGroovyMethods.inspect(object));
+ renderView = false;
+ }
+ catch (IOException e) {
+ throw new ControllerExecutionException("I/O error obtaining response writer: " + e.getMessage(), e);
+ }
+ return renderView;
+ }
+
+ private void renderTemplateForCollection(GrailsWebRequest webRequest, View view, Map binding, Object colObject, String var) throws IOException {
+ if (colObject instanceof Iterable) {
+ Iterable c = (Iterable) colObject;
+ for (Object o : c) {
+ if (GrailsStringUtils.isBlank(var)) {
+ binding.put(DEFAULT_ARGUMENT, o);
+ }
+ else {
+ binding.put(var, o);
+ }
+ renderViewForTemplate(webRequest, view, binding);
+ }
+ }
+ else {
+ if (GrailsStringUtils.isBlank(var)) {
+ binding.put(DEFAULT_ARGUMENT, colObject);
+ }
+ else {
+ binding.put(var, colObject);
+ }
+
+ renderViewForTemplate(webRequest, view, binding);
+ }
+ }
+
+ private void renderTemplateForBean(GrailsWebRequest webRequest, View view, Map binding, Object bean, String varName) throws IOException {
+ if (GrailsStringUtils.isBlank(varName)) {
+ binding.put(DEFAULT_ARGUMENT, bean);
+ }
+ else {
+ binding.put(varName, bean);
+ }
+ renderViewForTemplate(webRequest, view, binding);
+ }
+
+ private void renderView(GrailsWebRequest webRequest, Map argMap, Object target, GroovyObject controller) {
+ String viewName = argMap.get(ARGUMENT_VIEW).toString();
+ String viewUri = webRequest.getAttributes().getNoSuffixViewURI((GroovyObject) target, viewName);
+ String contextPath = getContextPath(webRequest, argMap);
+ if(contextPath != null) {
+ viewUri = contextPath + viewUri;
+ }
+ Object modelObject = argMap.get(ARGUMENT_MODEL);
+ if (modelObject != null) {
+ modelObject = argMap.get(ARGUMENT_MODEL);
+ boolean isPromise = modelObject instanceof Promise;
+ Collection<ActionResultTransformer> resultTransformers = getActionResultTransformers(webRequest);
+ for (ActionResultTransformer resultTransformer : resultTransformers) {
+ modelObject = resultTransformer.transformActionResult(webRequest,viewUri, modelObject);
+ }
+ if (isPromise) return;
+ }
+
+ applyContentType(webRequest.getCurrentResponse(), argMap, null);
+
+ Map model;
+ if (modelObject instanceof Map) {
+ model = (Map) modelObject;
+ }
+ else {
+ model = new HashMap();
+ }
+
+ controller.setProperty(ControllerDynamicMethods.MODEL_AND_VIEW_PROPERTY, new ModelAndView(viewUri, model));
+ }
+
+ private boolean renderJSON(Closure callable, HttpServletResponse response) {
+ boolean renderView = true;
+ JSONBuilder builder = new JSONBuilder();
+ JSON json = builder.build(callable);
+ json.render(response);
+ renderView = false;
+ return renderView;
+ }
+
+ private boolean renderMarkup(Closure closure, HttpServletResponse response) {
+ StreamingMarkupBuilder b = new StreamingMarkupBuilder();
+ b.setEncoding(response.getCharacterEncoding());
+ Writable markup = b.bind(closure);
+ return renderWritable(markup, response);
+ }
+
+ private boolean renderText(CharSequence text, HttpServletResponse response) {
+ try {
+ PrintWriter writer = response.getWriter();
+ return renderText(text, writer);
+ }
+ catch (IOException e) {
+ throw new ControllerExecutionException(e.getMessage(), e);
+ }
+ }
+
+ private boolean renderWritable(Writable writable, HttpServletResponse response) {
+ try {
+ PrintWriter writer = response.getWriter();
+ writable.writeTo(writer);
+ writer.flush();
+ }
+ catch (IOException e) {
+ throw new ControllerExecutionException(e.getMessage(), e);
+ }
+ return false;
+ }
+
+ private boolean renderText(CharSequence text, Writer writer) {
+ try {
+ if (writer instanceof PrintWriter) {
+ ((PrintWriter)writer).print(text);
+ }
+ else {
+ writer.write(text.toString());
+ }
+ writer.flush();
+ return false;
+ }
+ catch (IOException e) {
+ throw new ControllerExecutionException(e.getMessage(), e);
+ }
+ }
+
+ private boolean isJSONResponse(HttpServletResponse response) {
+ String contentType = response.getContentType();
+ return contentType != null && (contentType.indexOf("application/json") > -1 ||
+ contentType.indexOf("text/json") > -1);
+ }
}
View
190 ...llers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RedirectDynamicMethod.java
@@ -1,190 +0,0 @@
-/*
- * Copyright 2004-2005 the original author or authors.
- *
- * 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.codehaus.groovy.grails.web.metaclass;
-
-import grails.util.GrailsUtil;
-import groovy.lang.Closure;
-import groovy.lang.GroovyObject;
-import groovy.lang.MissingMethodException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import grails.util.GrailsClassUtils;
-import grails.core.GrailsControllerClass;
-import grails.web.mapping.LinkGenerator;
-import grails.web.mapping.ResponseRedirector;
-import grails.web.util.GrailsApplicationAttributes;
-import org.grails.web.servlet.mvc.GrailsWebRequest;
-import grails.web.mapping.mvc.RedirectEventListener;
-import org.springframework.context.ApplicationContext;
-import org.springframework.validation.Errors;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.servlet.support.RequestDataValueProcessor;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-/**
- * Implements the "redirect" Controller method for action redirection.
- *
- * @author Graeme Rocher
- * @since 0.2
- *
- * Created Oct 27, 2005
- */
-public class RedirectDynamicMethod extends AbstractDynamicMethodInvocation {
-
- public static final String METHOD_SIGNATURE = "redirect";
- public static final Pattern METHOD_PATTERN = Pattern.compile('^'+METHOD_SIGNATURE+'$');
- public static final String GRAILS_VIEWS_ENABLE_JSESSIONID = "grails.views.enable.jsessionid";
- public static final String GRAILS_REDIRECT_ISSUED = GrailsApplicationAttributes.REDIRECT_ISSUED;
-
- public static final String ARGUMENT_ERRORS = "errors";
-
- public static final String ARGUMENT_PERMANENT = "permanent";
-
- private static final Log LOG = LogFactory.getLog(RedirectDynamicMethod.class);
- private static final String BLANK = "";
- private boolean useJessionId = false;
- private Collection<RedirectEventListener> redirectListeners;
- private LinkGenerator linkGenerator;
- private RequestDataValueProcessor requestDataValueProcessor;
-
- /**
- */
- public RedirectDynamicMethod(Collection<RedirectEventListener> redirectListeners) {
- super(METHOD_PATTERN);
- this.redirectListeners = redirectListeners;
- }
-
- /**
- * @param applicationContext The ApplicationContext
- * @deprecated Here fore compatibility, will be removed in a future version of Grails
- */
- @Deprecated
- public RedirectDynamicMethod(ApplicationContext applicationContext) {
- super(METHOD_PATTERN);
- }
-
- public RedirectDynamicMethod() {
- super(METHOD_PATTERN);
- }
-
- public void setLinkGenerator(LinkGenerator linkGenerator) {
- this.linkGenerator = linkGenerator;
- }
-
- public void setRedirectListeners(Collection<RedirectEventListener> redirectListeners) {
- this.redirectListeners = redirectListeners;
- }
-
- public void setUseJessionId(boolean useJessionId) {
- this.useJessionId = useJessionId;
- }
-
- @SuppressWarnings({"unchecked","rawtypes"})
- @Override
- public Object invoke(Object target, String methodName, Object[] arguments) {
- if (arguments.length == 0) {
- throw new MissingMethodException(METHOD_SIGNATURE,target.getClass(),arguments);
- }
-
- Map argMap = arguments[0] instanceof Map ? (Map)arguments[0] : Collections.EMPTY_MAP;
- if (argMap.isEmpty()) {
- throw new MissingMethodException(METHOD_SIGNATURE,target.getClass(),arguments);
- }
-
- GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
- HttpServletRequest request = webRequest.getCurrentRequest();
- HttpServletResponse response = webRequest.getCurrentResponse();
-
- if(target instanceof GroovyObject) {
- GroovyObject controller = (GroovyObject)target;
-
- // if there are errors add it to the list of errors
- Errors controllerErrors = (Errors)controller.getProperty(ControllerDynamicMethods.ERRORS_PROPERTY);
- Errors errors = (Errors)argMap.get(ARGUMENT_ERRORS);
- if (controllerErrors != null && errors != null) {
- controllerErrors.addAllErrors(errors);
- }
- else {
- controller.setProperty(ControllerDynamicMethods.ERRORS_PROPERTY, errors);
- }
- Object action = argMap.get(GrailsControllerClass.ACTION);
- if (action != null) {
- argMap.put(GrailsControllerClass.ACTION, establishActionName(action,controller));
- }
- if (!argMap.containsKey(GrailsControllerClass.NAMESPACE_PROPERTY)) {
- // this could be made more efficient if we had a reference to the GrailsControllerClass object, which
- // has the namespace property accessible without needing reflection
- argMap.put(GrailsControllerClass.NAMESPACE_PROPERTY, GrailsClassUtils.getStaticFieldValue(controller.getClass(), GrailsControllerClass.NAMESPACE_PROPERTY));
- }
- }
-
- ResponseRedirector redirector = new ResponseRedirector(getLinkGenerator(webRequest));
- redirector.setRedirectListeners(redirectListeners);
- redirector.setRequestDataValueProcessor(initRequestDataValueProcessor());
- redirector.setUseJessionId(useJessionId);
- redirector.redirect(request, response, argMap);
- return null;
- }
-
- private LinkGenerator getLinkGenerator(GrailsWebRequest webRequest) {
- if (linkGenerator == null) {
- ApplicationContext applicationContext = webRequest.getApplicationContext();
- if (applicationContext != null) {
- linkGenerator = applicationContext.getBean("grailsLinkGenerator", LinkGenerator.class);
- }
- }
-
- return linkGenerator;
- }
-
-
- /*
- * Figures out the action name from the specified action reference (either a string or closure)
- */
- private String establishActionName(Object actionRef, Object target) {
- String actionName = null;
- if (actionRef instanceof String) {
- actionName = (String)actionRef;
- }
- else if (actionRef instanceof CharSequence) {
- actionName = actionRef.toString();
- }
- else if (actionRef instanceof Closure) {
- GrailsUtil.deprecated("Using a closure reference in the 'action' argument of the 'redirect' method is deprecated. Please change to use a String.");
- actionName = GrailsClassUtils.findPropertyNameForValue(target, actionRef);
- }
- return actionName;
- }
-
- /**
- * getter to obtain RequestDataValueProcessor from
- */
- private RequestDataValueProcessor initRequestDataValueProcessor() {
- GrailsWebRequest webRequest = (GrailsWebRequest)RequestContextHolder.currentRequestAttributes();
- ApplicationContext applicationContext = webRequest.getApplicationContext();
- if (requestDataValueProcessor == null && applicationContext.containsBean("requestDataValueProcessor")) {
- requestDataValueProcessor = applicationContext.getBean("requestDataValueProcessor", RequestDataValueProcessor.class);
- }
- return requestDataValueProcessor;
- }
-
-}
View
626 ...rollers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RenderDynamicMethod.java
@@ -15,63 +15,6 @@
*/
package org.codehaus.groovy.grails.web.metaclass;
-import grails.async.Promise;
-import grails.converters.JSON;
-import grails.util.GrailsWebUtil;
-import grails.web.JSONBuilder;
-import groovy.lang.Closure;
-import groovy.lang.GroovyObject;
-import groovy.lang.GroovyRuntimeException;
-import groovy.lang.MissingMethodException;
-import groovy.lang.Writable;
-import groovy.text.Template;
-import groovy.util.slurpersupport.GPathResult;
-import groovy.xml.StreamingMarkupBuilder;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import grails.util.GrailsStringUtils;
-import org.codehaus.groovy.grails.io.support.GrailsIOUtils;
-import org.codehaus.groovy.grails.io.support.GrailsResourceUtils;
-import org.codehaus.groovy.grails.io.support.IOUtils;
-import org.codehaus.groovy.grails.plugins.GrailsPlugin;
-import org.codehaus.groovy.grails.plugins.GrailsPluginManager;
-import org.grails.web.support.ResourceAwareTemplateEngine;
-import org.codehaus.groovy.grails.web.converters.Converter;
-import org.codehaus.groovy.grails.web.json.JSONElement;
-import grails.web.mime.MimeType;
-import grails.web.mime.MimeUtility;
-import org.codehaus.groovy.grails.web.pages.GroovyPageTemplate;
-import grails.web.util.GrailsApplicationAttributes;
-import grails.web.http.HttpHeaders;
-import org.grails.web.servlet.mvc.ActionResultTransformer;
-import org.grails.web.servlet.mvc.GrailsWebRequest;
-import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException;
-import org.codehaus.groovy.grails.web.servlet.view.GroovyPageView;
-import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutDecoratorMapper;
-import org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutView;
-import org.codehaus.groovy.grails.web.sitemesh.GroovyPageLayoutFinder;
-import org.codehaus.groovy.runtime.DefaultGroovyMethods;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.web.context.request.RequestAttributes;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.servlet.ModelAndView;
-import org.springframework.web.servlet.View;
-
/**
* Allows rendering of text, views, and templates to the response
*
@@ -79,10 +22,8 @@
* @since 0.2
*/
@SuppressWarnings({"unchecked","rawtypes"})
-public class RenderDynamicMethod extends AbstractDynamicMethodInvocation {
+public class RenderDynamicMethod {
public static final String METHOD_SIGNATURE = "render";
- public static final Pattern METHOD_PATTERN = Pattern.compile('^' + METHOD_SIGNATURE + '$');
-
public static final String ARGUMENT_TEXT = "text";
public static final String ARGUMENT_STATUS = "status";
public static final String ARGUMENT_LAYOUT = "layout";
@@ -96,562 +37,13 @@
public static final String ARGUMENT_COLLECTION = "collection";
public static final String ARGUMENT_BUILDER = "builder";
public static final String ARGUMENT_VAR = "var";
- private static final String DEFAULT_ARGUMENT = "it";
- private static final String BUILDER_TYPE_JSON = "json";
-
- private static final String TEXT_HTML = "text/html";
- private static final String APPLICATION_XML = "application/xml";
public static final String DISPOSITION_HEADER_PREFIX = "attachment;filename=";
- private String gspEncoding = DEFAULT_ENCODING;
- private static final String DEFAULT_ENCODING = "utf-8";
- private Object ARGUMENT_PLUGIN = "plugin";
- private static final String ARGUMENT_FILE = "file";
- private static final String ARGUMENT_FILE_NAME = "fileName";
- private MimeUtility mimeUtility;
- private Collection<ActionResultTransformer> actionResultTransformers;
-
- public RenderDynamicMethod() {
- super(METHOD_PATTERN);
- }
-