Permalink
Browse files

Multiple changes...

  • Loading branch information...
1 parent 8104cc6 commit ac8eb29f1f6d7bb05245e11367110a5db135ad28 @bwolff committed Apr 16, 2013
View
72 src/groovy/grails/plugins/rwt/EntryPointConfigurationBean.groovy
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright 2012-2013 Benjamin Wolff
+ *
+ * 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.
+ *
+ * Contributors:
+ * Benjamin Wolff - initial API and implementation
+ ******************************************************************************/
+package grails.plugins.rwt
+
+import org.eclipse.rap.rwt.client.WebClient
+
+/**
+ * Simple pogo that encapsulates the configuration for an RWT entry point. A list of these object is
+ * created according to the Config.groovy configuration and passed to the
+ * {@link ApplicationConfigurationBean}, which uses it to register the entry point.
+ *
+ * @author Benjamin Wolff
+ */
+class EntryPointConfigurationBean {
+
+ String name
+ String path
+ String entryPointBeanName
+ String pageTitle
+ String favicon
+ String themeId
+ String headHtml
+ String bodyHtml
+
+ /**
+ * Returns a map of the configured entry point properties according to the {@link WebClient}
+ * constants.
+ *
+ * @return A map of the configured entry point properties. Never null.
+ */
+ Map<String, String> getEntryPointProperties() {
+ Map<String, String> properties = [:]
+
+ if (pageTitle) {
+ properties[WebClient.PAGE_TITLE] = pageTitle
+ }
+
+ if (favicon) {
+ properties[WebClient.FAVICON] = favicon
+ }
+
+ if (themeId) {
+ properties[WebClient.THEME_ID] = themeId
+ }
+
+ if (headHtml) {
+ properties[WebClient.HEAD_HTML] = headHtml
+ }
+
+ if (bodyHtml) {
+ properties[WebClient.BODY_HTML] = bodyHtml
+ }
+
+ return properties
+ }
+}
View
74 src/groovy/grails/plugins/rwt/EntryPointConfigurationHelper.groovy
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright 2012-2013 Benjamin Wolff
+ *
+ * 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.
+ *
+ * Contributors:
+ * Benjamin Wolff - initial API and implementation
+ ******************************************************************************/
+package grails.plugins.rwt
+
+import groovy.util.logging.Commons;
+
+import org.codehaus.groovy.grails.exceptions.GrailsConfigurationException
+
+/**
+ * This class helps to extract the RWT entry point configurations from the Grails config. It also
+ * provides utility methods to work with these configurations.
+ *
+ * @author Benjamin Wolff
+ */
+@Commons
+class EntryPointConfigurationHelper {
+
+ final List<EntryPointConfigurationBean> entryPointConfigurations = []
+
+ public EntryPointConfigurationHelper(ConfigObject grailsConfig) {
+ extractEntryPointConfigurations(grailsConfig)
+ }
+
+ Boolean hasEntryPoints() {
+ return !entryPointConfigurations.isEmpty()
+ }
+
+ List<String> getEntryPointPaths() {
+ return entryPointConfigurations.collect { it.path }
+ }
+
+ private void extractEntryPointConfigurations(ConfigObject grailsConfig) {
+ grailsConfig.rwt.entrypoints.each { String name, values ->
+ String entryPointBeanName = values.bean ?: null
+
+ if (!entryPointBeanName) {
+ throw new GrailsConfigurationException("[RWT] Missing \"bean\" value for" +
+ " entry point configuration: ${name}")
+ }
+
+ String themeId = values.theme ?: null
+ if (themeId) {
+ themeId = themeId.toLowerCase() // Ignore capitalization.
+ }
+
+ def entryPointConfiguration = new EntryPointConfigurationBean()
+ entryPointConfiguration.name = name
+ entryPointConfiguration.path = '/' + name // The name of the entry point determines the URL path.
+ entryPointConfiguration.entryPointBeanName = entryPointBeanName
+ entryPointConfiguration.pageTitle = values.pageTitle ?: null
+ entryPointConfiguration.favicon = values.favicon ?: null
+ entryPointConfiguration.themeId = themeId
+ entryPointConfiguration.headHtml = values.headHtml ?: null
+ entryPointConfiguration.bodyHtml = values.bodyHtml ?: null
+ entryPointConfigurations << entryPointConfiguration
+ }
+ }
+}
View
40 src/groovy/grails/plugins/rwt/GrailsRwtEntryPointFactory.groovy
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright 2012-2013 Benjamin Wolff
+ *
+ * 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.
+ *
+ * Contributors:
+ * Benjamin Wolff - initial API and implementation
+ ******************************************************************************/
+package grails.plugins.rwt
+
+import org.eclipse.rap.rwt.application.EntryPoint
+import org.eclipse.rap.rwt.application.EntryPointFactory
+
+/**
+ * Simple implementation of an {@link EntryPointFactory}. A concrete {@link EntryPoint}
+ * implementing object can be set, which is then returned by the {@link #create()} method.
+ * <p>
+ * This factory implementation is used to be passed to the entry point configuration in the
+ * {@link ApplicationConfigurationBean}.
+ *
+ * @author Benjamin Wolff
+ */
+class GrailsRwtEntryPointFactory implements EntryPointFactory {
+
+ EntryPoint entryPoint
+
+ EntryPoint create() {
+ return entryPoint
+ }
+}
View
38 src/groovy/grails/plugins/rwt/ThemeConfigurationBean.groovy
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2012-2013 Benjamin Wolff
+ *
+ * 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.
+ *
+ * Contributors:
+ * Benjamin Wolff - initial API and implementation
+ ******************************************************************************/
+package grails.plugins.rwt
+
+/**
+ * Simple pogo that encapsulates the configuration for an RWT theme. A list of these object is
+ * created according to the Config.groovy configuration and passed to the
+ * {@link ApplicationConfigurationBean}, which uses it to register the theme.
+ *
+ * @author Benjamin Wolff
+ */
+class ThemeConfigurationBean {
+
+ public static final String DEFAULT_THEME_ID = 'rwtdefault'
+
+ String themeId
+ List<String> themeFilePaths
+
+ Boolean isDefaultTheme() {
+ return DEFAULT_THEME_ID == themeId
+ }
+}
View
66 src/groovy/grails/plugins/rwt/ThemeConfigurationHelper.groovy
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright 2012-2013 Benjamin Wolff
+ *
+ * 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.
+ *
+ * Contributors:
+ * Benjamin Wolff - initial API and implementation
+ ******************************************************************************/
+package grails.plugins.rwt
+
+import groovy.util.logging.Commons;
+
+import org.codehaus.groovy.grails.exceptions.GrailsConfigurationException
+
+/**
+ * This class helps to extract the RWT theme configurations from the Grails config. It also
+ * provides utility methods to work with these configurations.
+ *
+ * @author Benjamin Wolff
+ */
+@Commons
+class ThemeConfigurationHelper {
+
+ final List<ThemeConfigurationBean> themeConfigurations = []
+
+ public ThemeConfigurationHelper(ConfigObject grailsConfig) {
+ extractThemeConfigurations(grailsConfig)
+ }
+
+ Boolean hasThemes() {
+ return !themeConfigurations.isEmpty()
+ }
+
+ Boolean hasThemeId(String themeId) {
+ return themeConfigurations.find { it.themeId == themeId } != null
+ }
+
+ private void extractThemeConfigurations(ConfigObject grailsConfig) {
+ grailsConfig.rwt.themes.each { String name, value ->
+ def themeConfiguration = new ThemeConfigurationBean()
+ themeConfiguration.themeId = name.toLowerCase() // Ignore capitalization.
+
+ if (value instanceof List) {
+ themeConfiguration.themeFilePaths = value
+ } else if (value instanceof String) {
+ themeConfiguration.themeFilePaths = [value]
+ } else {
+ throw new GrailsConfigurationException("[RWT] Invalid value for theme \"${name}\"." +
+ " The value needs to be a string denoting the CSS file in the classpath," +
+ " or a list of path strings.")
+ }
+
+ themeConfigurations << themeConfiguration
+ }
+ }
+}

0 comments on commit ac8eb29

Please sign in to comment.