001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008-2010 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.tapestry.core;
016
017 import org.apache.tapestry5.internal.services.ResourceCache;
018 import org.apache.tapestry5.ioc.Configuration;
019 import org.apache.tapestry5.ioc.MappedConfiguration;
020 import org.apache.tapestry5.ioc.ObjectLocator;
021 import org.apache.tapestry5.ioc.OrderedConfiguration;
022 import org.apache.tapestry5.ioc.ServiceBinder;
023 import org.apache.tapestry5.ioc.annotations.Marker;
024 import org.apache.tapestry5.ioc.annotations.Symbol;
025 import org.apache.tapestry5.services.AssetFactory;
026 import org.apache.tapestry5.services.BindingFactory;
027 import org.apache.tapestry5.services.BindingSource;
028 import org.apache.tapestry5.services.Dispatcher;
029 import org.apache.tapestry5.services.LibraryMapping;
030 import org.apache.tapestry5.services.javascript.JavaScriptStack;
031 import org.chenillekit.tapestry.core.factories.ListBindingFactory;
032 import org.chenillekit.tapestry.core.factories.LoopBindingFactory;
033 import org.chenillekit.tapestry.core.factories.MessageFormatBindingFactory;
034 import org.chenillekit.tapestry.core.factories.OgnlBindingFactory;
035 import org.chenillekit.tapestry.core.factories.URIAssetFactory;
036 import org.chenillekit.tapestry.core.services.URIAssetAliasManager;
037 import org.chenillekit.tapestry.core.services.URIProvider;
038 import org.chenillekit.tapestry.core.services.impl.URIAssetAliasManagerImpl;
039 import org.chenillekit.tapestry.core.services.impl.URIDispatcher;
040 import org.chenillekit.tapestry.core.services.impl.YahooStack;
041
042 /**
043 * module for chenillekit web module.
044 *
045 * @version $Id: ChenilleKitCoreModule.java 675 2010-07-30 14:49:17Z homburgs $
046 */
047 public class ChenilleKitCoreModule
048 {
049 public void contributeComponentClassResolver(Configuration<LibraryMapping> configuration)
050 {
051 configuration.add(new LibraryMapping("chenillekit", "org.chenillekit.tapestry.core"));
052 configuration.add(new LibraryMapping("ck", "org.chenillekit.tapestry.core"));
053 }
054
055 public void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
056 {
057 // This is designed to make it easy to keep syncrhonized with FCKeditor. As we
058 // support a new version, we create a new folder, and update the path entry. We can then
059 // delete the old version folder (or keep it around). This should be more manageable than
060 // ovewriting the local copy with updates. There's also a ClasspathAliasManager
061 // contribution based on the path.
062 configuration.add("ck.components", "org/chenillekit/tapestry/core/components");
063 configuration.add("ck.fckeditor", "classpath:${ck.components}/fckeditor");
064
065 configuration.add("yahoo.yui.path", "org/chenillekit/tapestry/core/yui_2_8_0");
066 configuration.add("yahoo.yui", "classpath:${yahoo.yui.path}");
067
068 configuration.add("yahoo.yui.mode", "-min");
069 }
070
071 public void contributeClasspathAssetAliasManager(MappedConfiguration<String, String> configuration,
072 @Symbol("ck.components") String scriptPath)
073 {
074 configuration.add("fckeditor/", scriptPath + "/fckeditor/");
075 configuration.add("window/", scriptPath + "/window/");
076 }
077
078 public void contributeBindingSource(MappedConfiguration<String, BindingFactory> configuration,
079 BindingSource bindingSource)
080 {
081 configuration.add("messageformat", new MessageFormatBindingFactory(bindingSource));
082 configuration.add("list", new ListBindingFactory(bindingSource));
083 configuration.add("loop", new LoopBindingFactory(bindingSource));
084 configuration.add("ognl", new OgnlBindingFactory());
085 }
086
087 @Marker(URIProvider.class)
088 public AssetFactory buildURIAssetFactory(ResourceCache resourceCache, URIAssetAliasManager aliasManager)
089 {
090 return new URIAssetFactory(resourceCache, aliasManager);
091 }
092
093 public void contributeAssetSource(MappedConfiguration<String, AssetFactory> configuration,
094 @URIProvider AssetFactory uriAssetFactory)
095 {
096 configuration.add(ChenilleKitCoreConstants.URI_PREFIX, uriAssetFactory);
097 }
098
099 public static void bind(ServiceBinder binder)
100 {
101 binder.bind(URIAssetAliasManager.class, URIAssetAliasManagerImpl.class);
102 }
103
104 /**
105 * The MasterDispatcher is a chain-of-command of individual Dispatchers, each handling (like a servlet) a particular
106 * kind of incoming request.
107 */
108 public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration,
109 ObjectLocator locator)
110 {
111 configuration.add("Uri", locator.autobuild(URIDispatcher.class), "before:Asset");
112
113 }
114
115 /**
116 * Contributes the "yahoo" {@link org.apache.tapestry5.services.javascript.JavaScriptStack}s
117 */
118 public static void contributeJavaScriptStackSource(MappedConfiguration<String, JavaScriptStack> configuration)
119 {
120 configuration.addInstance("yahoo", YahooStack.class);
121 }
122 }