tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andy...@apache.org
Subject svn commit: r594133 - in /tapestry/tapestry4/trunk/tapestry-framework/src: descriptor/META-INF/ java/org/apache/tapestry/javascript/
Date Mon, 12 Nov 2007 13:49:41 GMT
Author: andyhot
Date: Mon Nov 12 05:49:40 2007
New Revision: 594133

URL: http://svn.apache.org/viewvc?rev=594133&view=rev
Log:
javascript manager for handling js libraries and an ajax delegate that uses it

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.js.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManager.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java

Added: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.js.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.js.xml?rev=594133&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.js.xml (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.js.xml Mon
Nov 12 05:49:40 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!-- 
+   Copyright 2007 The Apache Software Foundation
+
+   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.
+-->
+
+<module id="tapestry.js" version="4.0.0" package="org.apache.tapestry.javascript">
+
+    Module for javascript support.
+
+    <service-point id="JavascriptManager">
+        Manages javascript files of 3rd party libraries.
+
+        <invoke-factory>
+            <construct class="JavascriptManagerImpl">
+                <set-service property="assetSource" service-id="tapestry.asset.AssetSource"/>
+                <set property="files" value="classpath:/dojo-0.4.3/dojo.js"/>
+                <set property="formFiles" value="classpath:/dojo-0.4.3/dojo2.js"/>
+                <set property="widgetFiles" value="classpath:/dojo-0.4.3/dojo3.js"/>
+                <set property="path" value="classpath:/dojo-0.4.3/"/>
+                <set property="tapestryFile" value="classpath:/tapestry/core.js"/>
+                <set property="tapestryPath" value="classpath:/tapestry/"/>
+            </construct>
+        </invoke-factory>
+
+    </service-point>
+    
+</module>
\ No newline at end of file

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManager.java?rev=594133&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManager.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManager.java
Mon Nov 12 05:49:40 2007
@@ -0,0 +1,68 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// 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.apache.tapestry.javascript;
+
+import java.util.List;
+
+import org.apache.tapestry.IAsset;
+
+/**
+ * Manages javascript files of 3rd party libraries.
+ */
+public interface JavascriptManager {
+    /**
+     * The javascript files that should always be included.
+     * @return A not-null (but possibly empty) list of {@link IAsset}s.
+     */
+    List getJsAssets();
+
+    IAsset getMainJsAsset();
+
+    /**
+     * The javascript files that provide form-related functionality.
+     * They're dynamically included when the page contains forms.
+     * @return A not-null (but possibly empty) list of {@link IAsset}s.
+     */
+    List getJsFormAssets();
+    
+    IAsset getMainJsFormAsset();
+
+    /**
+     * The javascript files that provide widget-related functionality.
+     * They're dynamically included when the page contains widgets.
+     * @return A not-null (but possibly empty) list of {@link IAsset}s.
+     */
+    List getJsWidgetAssets();
+
+    IAsset getMainJsWidgetAsset();
+
+    /**
+     * The base path to the javascript files.
+     * @return if null, it is left unused.
+     */
+    IAsset getJsPath();
+
+    /**
+     * The tapestry js file.
+     * @return if null then no tapestry file is included.
+     */
+    IAsset getJsTapestryAsset();
+
+    /**
+     * The base path to the tapestry js files.
+     * @return if null, it is left unused.
+     */
+    IAsset getJsTapestryPath();
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java?rev=594133&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
Mon Nov 12 05:49:40 2007
@@ -0,0 +1,149 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// 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.apache.tapestry.javascript;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.hivemind.Location;
+import org.apache.hivemind.util.URLResource;
+import org.apache.tapestry.IAsset;
+import org.apache.tapestry.TapestryUtils;
+import org.apache.tapestry.asset.AssetSource;
+import org.apache.tapestry.util.DescribedLocation;
+
+/**
+ * @author Andreas Andreou
+ * @since 4.1.4
+ */
+public class JavascriptManagerImpl implements JavascriptManager {
+
+    public IAsset getMainJsAsset()
+    {
+        return findFirst(_files);
+    }
+
+    public IAsset getMainJsFormAsset()
+    {
+        return findFirst(_formFiles);
+    }
+
+    public IAsset getMainJsWidgetAsset()
+    {
+        return findFirst(_widgetFiles);
+    }
+
+    public List getJsAssets()
+    {
+        return _files;
+    }
+
+    public List getJsFormAssets()
+    {
+        return _formFiles;
+    }
+
+    public List getJsWidgetAssets()
+    {
+        return _widgetFiles;
+    }
+
+    public IAsset getJsPath()
+    {
+        return _path;
+    }
+
+    public IAsset getJsTapestryAsset()
+    {
+        return _tapestryFile;
+    }
+
+    public IAsset getJsTapestryPath()
+    {
+        return _tapestryPath;
+    }
+
+    public void setFiles(String files)
+    {
+        _files = buildAssetList(files, "files");
+    }
+
+    public void setFormFiles(String formFiles)
+    {
+        _formFiles = buildAssetList(formFiles, "formFiles");
+    }
+
+    public void setWidgetFiles(String widgetFiles)
+    {
+        _widgetFiles = buildAssetList(widgetFiles, "widgetFiles");
+    }
+
+    public void setPath(String path)
+    {
+        _path = findAsset(path, "path");
+    }
+
+    public void setTapestryFile(String tapestryFile)
+    {
+        _tapestryFile = findAsset(tapestryFile, "tapestryFile");
+    }
+
+    public void setTapestryPath(String tapestryPath)
+    {
+        _tapestryPath = findAsset(tapestryPath, "tapestryPath");
+    }
+
+    public void setAssetSource(AssetSource assetSource)
+    {
+        _assetSource = assetSource;
+    }
+
+    private List buildAssetList(String files, String name) {
+        String[] js = TapestryUtils.split(files);
+        List list = new ArrayList(js.length);
+        for (int i=0; i<js.length; i++) {
+            list.add(findAsset(js[i], name + i));
+        }
+        return list;
+    }
+
+    private IAsset findAsset(String path, String description)
+    {
+        IAsset asset = null;
+        if (path!=null)
+        {
+            Location location = new DescribedLocation(new URLResource(path), description);
+            asset = _assetSource.findAsset(null, path, null, location);
+        }
+        System.out.println("##ASSET for " + path + " : " + asset);
+        return asset;
+    }
+
+    private IAsset findFirst(List list) {
+        if (list ==null || list.isEmpty())
+            return null;
+        else
+            return (IAsset) list.get(0);
+    }
+
+    private List _files;
+    private List _formFiles;
+    private List _widgetFiles;
+    private IAsset _path;
+    private IAsset _tapestryFile;
+    private IAsset _tapestryPath;
+
+    private AssetSource _assetSource;
+}

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java?rev=594133&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java
Mon Nov 12 05:49:40 2007
@@ -0,0 +1,77 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// 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.apache.tapestry.javascript;
+
+import java.util.List;
+
+import org.apache.tapestry.IAsset;
+import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IRender;
+import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.IPage;
+
+/**
+ * Outputs the main js packages and the tapestry js 
+ * that are defined by the {@link JavascriptManager} service.
+ */
+public class SimpleAjaxShellDelegate implements IRender {
+
+    private static final String SYSTEM_NEWLINE= (String)java.security.AccessController.doPrivileged(
+      new sun.security.action.GetPropertyAction("line.separator"));
+
+    private JavascriptManager _javascriptManager;
+
+    public SimpleAjaxShellDelegate(JavascriptManager javascriptManager) {
+        _javascriptManager = javascriptManager;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void render(IMarkupWriter writer, IRequestCycle cycle)
+    {
+        IPage page = cycle.getPage();
+        StringBuffer str = new StringBuffer();
+        // include all the main js packages
+        appendAssetsAsJavascript(str, _javascriptManager.getJsAssets());
+        if (page.hasFormComponents())
+        {
+            appendAssetsAsJavascript(str, _javascriptManager.getJsFormAssets());
+        }
+        if (page.hasWidgets())
+        {
+            appendAssetsAsJavascript(str, _javascriptManager.getJsWidgetAssets());
+        }
+        // include the tapestry js
+        IAsset tapestryAsset = _javascriptManager.getJsTapestryAsset();
+        if (tapestryAsset!=null)
+        {
+            str.append("<script type=\"text/javascript\" src=\"")
+                .append(tapestryAsset.buildURL()).append("\"></script>").append(SYSTEM_NEWLINE);
+        }
+
+        writer.printRaw(str.toString());
+        writer.println();
+    }
+
+    private void appendAssetsAsJavascript(StringBuffer str, List jsAssets) {
+        for (int i = 0; i < jsAssets.size(); i++)
+        {
+            IAsset asset = (IAsset) jsAssets.get(i);
+            str.append("<script type=\"text/javascript\" src=\"")
+                .append(asset.buildURL()).append("\"></script>").append(SYSTEM_NEWLINE);
+        }
+    }
+}



Mime
View raw message